It is impossible to make to routes in cakePHP?
example:
localhost/web/admin
localhost/web/tutor
It is impossible to make to routes in cakePHP?
example:
localhost/web/admin
localhost/web/tutor
Yes you can make route in app/config/routes.php file using Router::connect() pass the name of your route and one array which contains name of the controller and action.
Example:
Router::connect(’/admin’,array(‘controller’=>‘admin’,‘action’=>‘create’);
sorry i mean 2 routes, so it will be:
Router::connect(’/admin’,array(‘controller’=>‘admin’,‘action’=>‘create’);
Router::connect(’/user’,array(‘controller’=>‘admin’,‘action’=>‘create’);
is it possible?
yes you can create any number of routes in that file
but the problem is, when i entered localhost/web/user then i will direcred automatically to localhost/web/admin. why was that happpened?
You have to change controller name or action name or both for different routes
yes i have changed that, this is my routes for admin:
Router::connect(‘/admin’, array(‘admin’ => true,‘prefix’ => ‘admin’, ‘controller’ => ‘users’, ‘action’ => ‘login’));
Router::connect(‘/admin/:controller’, array(‘action’ => ‘index’, ‘prefix’ => ‘admin’, ‘admin’ => true));
Router::connect(‘/admin/:controller/:action/*’, array(‘admin’ => true,‘prefix’ => ‘admin’));
this is for user:
Router::connect(‘/user’, array(‘admin’ => true,‘prefix’ => ‘admin’, ‘controller’ => ‘users’, ‘action’ => ‘login_tutor’));
Router::connect(‘/user/:controller’, array(‘action’ => ‘index’, ‘prefix’ => ‘admin’, ‘admin’ => true));
Router::connect(‘/user/:controller/:action/*’, array(‘admin’ => true,‘prefix’ => ‘admin’));user
I think you must wrap it in prefix calls
can you tell me more? i should make 2 prefix in cake/config/routes.php?
Something like this
Router::prefix('admin', function (RouteBuilder $routes) {
$routes->connect('/', ['controller' => 'Users', 'action' => 'login']);
$routes->scope('/user', function (RouteBuilder $routes) {
$routes->connect('/:controller', ['action' => 'index'], ['routeClass' => 'DashedRoute']);
$routes->connect('/:controller/:action/*', [], ['routeClass' => 'DashedRoute']);
});
$routes->fallbacks(DashedRoute::class);
});