Breaking News
You are here : Home / Web development / CakePHP / cakePHP 2.1 New Extending Views Feature
cakePHP Extending Views New Feature

cakePHP 2.1 New Extending Views Feature

cakePHP 2.1 New Extending Views Feature –

CakePHP Is awesome Framework.I Love working on cakePHP.Few Days back I migrated from cakePHP 1. to the New 2.1 stable Version of the CakePHP .CakePHP 2.1 Comes With inbuilt awesome Features.It makes Work more rapid,The Best New feature according to me is Extending views,This Extending the Views From a Parent View or Common template is an Awesome and Revolutionary CakePHP Feature.

So Today I m Gonna Write About this New Extending Views Feature of the CakePHP and put a nice Tutorial How to Use Extending Views Feature of the cakePHP.

cakePHP 2.1 New Extending Views Feature Tutorial –

Before Moving in to Extending Views Tutorial we’ll see some Basics.Like What is CakePHP Extending Views Feature?How to make Common Template or Parent View for Extending Views? Lets Move on and See.

What Is cakePHP Extending Views Feature ?

cakePHP’s Extending View’s Main Motive is DRY(Don’t Repeat Yourself).You can Create a Template View or a Common View And Inherit in all your views.Idea is to Wrap a view in another.So that you should not repeat same markup again and again.

[separator /]

How to Use cake’s Extending Views Feature –

To be able to use cake’s Extending View Feature We gonna Create a Common view ,which Will act as parent view for all other views which may use same mark up as parent.So now you will only have to create view’s layout once,then make it parent .Then just extend it to all your views.

The View Template or Parent View(Extending View)

The main View Template .Used By all the Views.This is simple parent template which will take sidebar ,content and title from child default if in child view we do not set ‘title’ and ‘sidebar’ in child then all content will be available in content variable.

The Child View Or Extender of parent-

The Child View Which Uses The Parent OR view Template.WE’ll set the variable that parent needed ,After setting variables the rest of the child view body will go in cake’s content (‘content variable’).So its quite easy,we just need to define here sidebar start to end and title variable in this case.The rest body will automatically put in content variable by cake.

Now this Child View have layout of the Parent view.You do not have to reuse the code.

[separator /]

Conclusion –

The new Feature is Awesome in cake and Make Framework Produce more reusable Code and Increase the Speed of Web application development.I have Enjoyed working in cake and migrated to cake 2 Due to this awesome New Extending Views Feature.I hope you liked this feature too.Keep visiting.

[separator /]

Tags : , , , ,

3 Replies

  1. ahsan says:

    “Blocks can only contain strings.”

    getting this error while doing as told by you…………i had remove previous error by putting ” inspite of as written above but m unable to solve this one as i am new in cakephp……… i had made complete made module on posts and all crud operations……….

    1. Ramandeep Singh says:

      You can find more reference no this topic on

  2. pandora says:

    made module on posts and all crud operation

Leave a Reply

Want to join the discussion ? Feel Free to contribute !