0

我有一个问题,有些重定向不起作用,有些重定向。我正在使用一种粗略的方式进行重定向,即在errorActionof 中捕获 url ErrorController,然后有一些 if 语句,然后执行如下重定向:

 public function errorAction()
    {
        $request = basename($this->getRequest()->getRequestUri());
        $this->getHelper('redirector')->setCode(301);
        if ($request == 'rand.html')
            $this->_redirect('/services/currency/rand');
        if ($request == 'dollar.html')
            $this->_redirect('/services/currency/dollar');
        if ($request == 'zim-dollar-currency.html')
            $this->_redirect('/services/currency/zim');

        //About 20 of these If statements

        $errors = $this->_getParam('error_handler');

        //load appearance stuff

        if (!$errors) {
            $this->view->message = 'You have reached the error page';
            return;
        }

        switch ($errors->type) {
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
                // 404 error -- controller or action not found
                $this->getResponse()->setHttpResponseCode(404);
                $priority = Zend_Log::NOTICE;
                $this->view->message = 'Page not found';
                $this->view->headTitle()->prepend('Page Not Found');
                break;
            default:
                // application error
                $this->getResponse()->setHttpResponseCode(500);
                $priority = Zend_Log::CRIT;
                $this->view->message = 'Application error';
                $this->view->headTitle()->prepend('Application error');
                break;
        }

        $this->view->request = $errors->request;
    }

所以,有些会起作用,有些不会,比如:zim-dollar-currency...

不知道为什么会这样。我什至检查了诸如 Windows 行尾之类的东西。没有...

4

1 回答 1

0

尝试使用带有默认操作的开关构造

于 2013-11-07T10:29:13.090 回答