Want to create a controller? There is 2 ways of creating it:
src/Controller
)bin/cake bake controller %controllerName%
command from CLI)If You want to create it manually, go to src/Controller
folder and create file that following next pattern:
([A-Z]{1}[a-z]{1,})Controller.php
In that controller, You should define namspace
, that will be used:
<?php
namespace App\Controller;
Then You should name it as filename, ex. AdminiController:
use App\Controller\AppController;
class AdminController extends AppController{}
Inside of this class, You should create Your first method, ex. login
:
public function login(){}
If You will type in Your browser : http://{{project-name}}/admin/login
it will throw an error of missing template. How to solve this problem?
You need to create under src/Template/Admin/
login.ctp
file.
Note : *.ctp wildcard - is Cake Template file, that is using to pass/render data You setting through controller.
In that file just type 'Hello World!' where You want, refresh page with template error and You will get Your World
, that greets You!
Note : By default,
src/Template/Layout/default.ctp
is rendering as layout, if You didn't defines one