cakephpcakephp-3.0cakephp-routing

CakePHP Layout template overriding view template


I have installed CakePHP 3.8 and my layout template (/src/Template/Layout/default.ctp) is completely overriding my controller view (src/Template/Users/login.ctp).

I have echo'd & die()'d at the beginning/end of both files, so I know they are being called/rendered, but once default.ctp is called/rendered, login.ctp is gone.

I think this a routing issue but I'm not sure. I'm new to install/setup of CakePHP. Any help would be greatly appreciated.


Solution

  • welcome to StackOverflow. I guess you misunderstood the functionality of the CakePHP templating.

    The layout files are supposed to override the view file. In CakePHP when a view renders first the layout is rendered and in that layout, the view is embedded in the place where you use the $this->fetch('content');.

    that's the reason why all the dynamic content is placed in the view file and common content like the header and all in the layout.

    I hope you got my point.

    In case you have still any doubt feel free to ask. I'll be happy to help.