Reusable code blocks in CakePhp 2

Posted by Randika on July 16, 2009

Many web applications has code blocks such as header areas, footer areas, navigation menus that need to be repeated from page to page. In Cake These reusable parts are called Elements. This short tutorial demonstrates how to create and reuse code block in cakephp.

All you needs do first is, find the /app/views/elements/ directory from your cakephp web app and create a new file with the .ctp extension. oh if you are using .thtml as your views extension no matter you can use it.

For this example I’m creating footer block for my cake app. in /app/views/elements/footer.ctp
Then add the codes that requires for the footer in that page.

and from my other views, now i can call for this block as

echo $this->element('footer');

Yeah, It’s that simple. Also you can pass data to an element through the element’s second argument:

echo $this->element('footer', array("var_foo"=>"bar"));

On your element now you can get that variable, as this variable is available as members of the parameter array.

echo $var_foo; //this will print "bar" as the output.

Favorite Quotes

Posted by Randika on July 04, 2009

Here are few quotes that I like, and I’ll update this page constantly when I find more. anyway most of the quotes you find here are computer-related. please contribute to the list by providing your favorite quotes as well.

“To have a great idea, have a lot of them.”
-Thomas Alva Edison

“The value of an idea lies in the using of it.”
- Thomas Alva Edison


“What I hear I forget, what I see I remember, what I do I understand.”

Confucius (Chines philosopher 551 BC – 479 BC)

“There are 10 kinds of people in the world, those that understand binary and those that don’t.”

“Good judgement comes from experience; experience comes from bad judgement.”

“Some people want it to happen, some wish it would happen, others make it happen.”
–Michael Jordan (American professional basketball player (NBA) born February 17, 1963)

“There are two ways of constructing a software design.  One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies.”
–C.A.R. Hoare

“The function of good software is to make the complex appear to be simple.”
–Grady Booch

“Any fool can use a computer.  Many do.”
–Ted Nelson

“Live as if you were to die tomorrow. Learn as if you were to live forever.”
– Mahatma Gandhi