Author Topic: Zend Admin path routing  (Read 2056 times)

0 Members and 1 Guest are viewing this topic.

Offline zinbielTopic starter

  • Irregular
  • Posts: 2
    • View Profile
Zend Admin path routing
« on: August 31, 2009, 07:59:38 AM »
Hello phpfreaks!  :shy:
I'm currently trying to recode my own libraries using the Zend framework. This is my problem:
By default Zend (the dispatcher?) upon access of let's say http://localhost/A/test is trying to Find an action 'testAction' in the 'A' controller.
This is fine for the public portion of my websites. However I'd like to use a different path parsing technique for the administrator interface:
I have created an AdminController which takes care of the login part. When someone authenticates I want them to be redirected to /admin/user/view and this url to be parsed as an action listAction in the UserController and not as userAction in AdminController.
Right now I'm using the redirector helper and I can forward it to the proper url with
Code: [Select]
$front=Zend_Controller_Front::getInstance();
$front->setBaseUrl('/admin/');
$this->_helper->redirector('view','User');
However I'd then have to rewrite the route for each class and action inside the /admin/ path which sounds wrong.
In addition to that, by simply rerouting let's say /admin/user/view to call viewAction in UserController the url helper seems to be still outputing /user/view. I would like to fix that as well so some Controllers' urls are looked for in /admin/ instead.
Can someone advice on a clean way to solve this?  :shrug:

Offline zinbielTopic starter

  • Irregular
  • Posts: 2
    • View Profile
Re: Zend Admin path routing
« Reply #1 on: September 09, 2009, 04:27:01 AM »
I'll answer this myself for anyone interested as I've solved it and moved way past it.
In my bootstrap file I've reconfigured routing as such:

Code: [Select]
$ctrl = Zend_Controller_Front::getInstance();
$router = $ctrl->getRouter();

For the login/logout function I wanted that handled by the AdminController and actions loginAction, logoutAction so:
Code: [Select]
$router->addRoute(
'admin_login',
new Zend_Controller_Router_Route('Admin/login', array('controller'=>'Admin','action'=>'login'))
);
$router->addRoute(
'admin_logout',
new Zend_Controller_Router_Route('Admin/logout', array('controller'=>'Admin','action'=>'logout'))
);

For the rest of the actions I wanted every remaining url in the admin area handled by seperate controllers. This is done like this:
Code: [Select]
$router->addRoute(
'Admin_generic',
new Zend_Controller_Router_Route('Admin/:controller/:action/*', array('module'=>'default'))
);