Wednesday, August 9, 2017

Cakephp: add a ctp file without controller

In CakePHP, usually, if you want to create a new page, you need to make its controller at first.
But if you use PagesController, you can add a ctp file super easily.

At first, create ctp file under \src\Template/Pages folder.

I created a test.ctp file under \src\Template/Pages.

Inside the file is:
<h1>Hello This is a test</h1>

Now you can access the file from browser without modifying controller or model. This is because Pages controller has a special function to display the ctp file.


The display function in PagesController. All you have to do is designate the file name.