Skip to content
Advertisement

How to call view in another view by using cakephp

I am just new CakePhp, i wonder how to call a view in another view.

When I started to run CakePhp the default layout is located in view/layouts/default.ctp.

In default.ctp I called a view name homeview (view/homes/homeview.ctp).

Here is my code:

JavaScript

And in the homeview.ctp I called another view named displayphone (view/homes/displayphone.ctp) homeview.ctp

JavaScript

displayphone.ctp

JavaScript

Why I can not call displayphone block in homeview ?

Advertisement

Answer

As you mentioned,

JavaScript

has created a block by name homeview, Refer this http://book.cakephp.org/2.0/en/views.html

As far as calling another view inside the view is not possible unless you create an element for that. Element are the common set of HTML which can be used in any view file throughout the project. For above purpose create an element by name “displayphone.ctp” in Element folder inside view and then call it like

JavaScript

Hope this will solve your purpose.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement