Cakephp Tips: Routing an Admin dashboard 3

Posted by Randika on September 09, 2009

I had some issues today with the admin routes of my XYZ :) cakephp app. I want the administrator to be able to type domainfoo.bar/admin and be directed to a log in. Then right after the authentication I want them to be redirected to admin_index of  the dashboards_controller (Admin’s Dashboard), So here is what I did for redirection.

1
$this->redirect(array('controller'=>'dashboards','action'=>'admin_index'));

But the problem is that I get the following error:

Private Method in DashboardsController

Error: DashboardsController::admin_index() cannot be accessed directly.

Notice: If you want to customize this error message, create app\views\errors\private_action.ctp

The issue is when using,

1
$this->redirect(array('controller'=>'dashboards','action'=>'admin_index'));

it tries to access the admin_index() function directly which is private as the URL goes domainfoo.bar/dashbords/admin_index

Instead we should set it as:

1
$this->redirect(array('controller'=>'dashboards','action'=>'index','admin'=>true));

or

1
$this->redirect(array('controller'=>'dashboards','action'=>'index','prefix'=>'admin'));

Hope this will help someone one day.

Do you think it's usefull? share it on
  • Twitter
  • Facebook
  • Google Bookmarks
  • Digg
  • del.icio.us
  • LinkedIn
  • StumbleUpon
  • Technorati
Trackbacks

Use this link to trackback from your own site.

  • Jatin200886
    You should first create Admin routing in config/core.php. Just write Configure::write('Routing.prefixes', array('admin')); (if using cake1.3) or Configure::write('Routing.admin', 'admin');
  • Thank you for sharing your experience and codes
  • webfacer.com
    Hei,

    i had make the same mistake as you and because i thought the action have to be the same as the method but it isn´t.

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

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

    You see you call the action without the prefix 'admin_' of the method only the method name.

    I hope everyone is helped out of the misery ;)
blog comments powered by Disqus