0

当有人写以下内容时,zend路由器应该是什么

http://domain.com/admin/news/edit/id/6

最后它路由到以下

http://domain.com/news/admin/edit/id/6

我可以使用任何控制器插件来做到这一点???

请帮我 ...

4

1 回答 1

1

我没有得到任何人的帮助。但最后我设法创建了一个控制器插件来解决这个问题。我发布这个,因为它可以帮助任何人......

class Layzend_Controller_Plugin_AdminRouter extends Zend_Controller_Plugin_Abstract
{
    public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
    {
        $module = $request->getModuleName(); 
        $controller = $request->getControllerName(); 
        $action = $request->getActionName();

        $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
        $options = $bootstrap->getOption('custom');
        $adminDirectory = $options['adminDirectory'];
        $adminDirectory = $adminDirectory ? $adminDirectory : 'admin';

        if($module == $adminDirectory)
        {
            $newModule = ($controller == 'index') ? 'default' : $controller;
            $newController = 'admin';
            $newAction = $action;

            $moduleDir = APPLICATION_PATH . "/modules/$newModule";
            if(!is_dir($moduleDir)) 
            {
                Zend_Layout::getMvcInstance()->setLayoutPath(APPLICATION_PATH . "/layouts/scripts/admin/");
                throw new Zend_Controller_Action_Exception('Page not found.',404);
            }

            $request->setModuleName($newModule);
            $request->setControllerName($newController);
            $request->setActionName($newAction);

        } 
        else if($module == 'admin') {
            throw new Zend_Controller_Action_Exception('Page not found.',404);
        }
    }
}
于 2011-09-18T20:12:24.847 回答