To map the URL controller action the feature that is used is routing and in CakePHP to make URLs more configurable and flexible routing is introduced. So in this tutorial we will see the process of Administration Prefix Routing with Cakephp 3.
In Cakephp 2 administration prefix routing is done in the following way:
Configure::write('Routing.prefixes', array('admin'));
In Cakehp 3, I was facing the issue to get the prefix routing work. Follow these steps :
In config/routes.php - add the following lines at the end of the routes.php file
Router::prefix('Admin', function ($routes) { $routes->fallbacks('InflectedRoute'); });
Now create new folder 'Admin' in src/Controller. Then in Controller folder create UsersController. Add the following line as a namespace at the first line in the file
namespace App\Controller\Admin;
Create the views.
In the Template folder create Admin folder. In the Admin folder create Users folder and dump all the add.ctp, edit.ctp, view.ctp files.
Thats all !
Thanks for reading the blog.
0 Comment(s)