質問

Im trying to put my app under /admin on cakephp. And i am trying to configure the admin routing. What im trying to achive is this:

Lets say the page is www.example.com so when the user type www.example.com/admin i want him/her to be redirected to the admin_dashboard.ctp (if it is logged in, otherwise redirect to log-in page). But now the problem is when i type www.example.com/admin it shows an error like:

Action PagesController::admin_index() could not be found

but if i do:

www.example.com/admin/users/dashboard it is redirected properly.

How can i achieve that? so just by typing /admin to redirect to dashboard??

and another thing is it possible to remove /users/ from url and just display admin/dashboard?

On core.php file i have added the following line:

Configure::write('Routing.prefixes', array('admin'));

And on the routes.php i have these lines :

Router::connect('/', array('controller' => 'users', 'action' => 'dashboard', 'dashboard'));

Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));

/* I added this line for admin routing */
        Router::connect('/admin', array('controller' => 'pages', 'action' => 'index', 'admin' => true));
役に立ちましたか?

解決

In routes.php write

 Router::connect('/admin', array('controller' => 'users', 'action' => 'dashboard', 'admin' => true));

instead of

 Router::connect('/admin', array('controller' => 'pages', 'action' => 'index', 'admin' => true));

This redirect you to admin_dashboard when you type www.example.com/admin.

他のヒント

Routing prefixes are added to the action name when looking for its corresponding method in the Controller.

In the Pages Controller rename your index() method into admin_index() as suggested by the error you are getting.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top