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.