implement Zend_Controller_Router_Interface
Here I would like to have a tree of controllers different from that offered by Zend. Let me explain, in many of my projects I find myself with controllers with over 1000 lines of code which is not very top side of code maintainability. So I want to cut my controllers, ie.
Example current controller:
UserController class extends Zend_Controller_Action {
listAction public function () {}
editAction public function () {}
.......
groupListAction public function () {}
groupEditAction public function () {}
.......
roleListAction public function () {}
roleEditAction public function () {}
.... etc.
}
So in this example I will like to outsource the concept of groups and roles in other controllers and other issues.
Desired architecture:
- controllers /
- UserController.php
- User /
--- GroupController.php
--- RoleController.php
-> url:
http://www.site.com/user/ -> class UserController
http://www.site.com/user_group/ -> class User_GroupController
http://www.site.com/user_role/ -> class User_RoleController
开发者_如何学运维
So I do not know how to apply this type of cutting.
If someone with an idea I'm interested. Thank you in advance.
Create a custom controller dispatcher. Class must implements Zend_Controller_Dispatcher_Interface, or you can extends Zend_Controller_Dispatcher_Standard.
The easiest way is to extend Zend_Controller_Dispatcher_Standard, because you will only need to override some of the parent methods.
class My_Dispatcher extends Zend_Controller_Dispatcher_Standard
{
public function isDispatchable(Zend_Controller_Request_Abstract $request)
{
// your code to find the correct class
}
public function loadClass($className)
{
// your code to load the correct class
// return the correct class name (e.g. User_RoleController)
}
public function getActionMethod(Zend_Controller_Request_Abstract $request)
{
// your code to find the correct method name
}
}
Set the new dispatcher class in your bootstrap:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
public function _initMyFrontController()
{
$this->bootstrap('frontController');
$frontController = $this->getResource('frontController');
$frontController->setDispatcher(new My_Dispatcher());
return $frontController;
}
}
thank you for your reply but i find the solution just by create custum routes. ie.
routes.core_user_group_index.type = "Zend_Controller_Router_Route_Static"
routes.core_user_group_index.route = "admin/core/user_group"
routes.core_user_group_index.defaults.module = "core"
routes.core_user_group_index.defaults.controller = "user_group"
routes.core_user_group_index.defaults.action = "index"
精彩评论