Randika Rathugama

Ruby on rails developer

Cakephp Tips: Routing an Admin Dashboard

| Comments

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.

$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,

$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:

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

or

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

Hope this will help someone one day.

Comments