Jump to content

Zend Admin path routing


zinbiel

Recommended Posts

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

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

Link to comment
Share on other sites

  • 2 weeks later...

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:

 

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

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

$router->addRoute(
'Admin_generic',
new Zend_Controller_Router_Route('Admin/:controller/:action/*', array('module'=>'default'))
);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.