Zend Framework: how to disable default routing?

I spent many hours trying to get this to work. And I was very desperate. It would be great if someone there could help me :)

Zend Framework 1.9.5 is currently in use, although I struggled to get this to work for many versions.

What I want to do is to provide my own routes through the XML configuration and make sure that everything that is not defined in my configuration will be on my errorController. (preferably so that I can stand out from EXCEPTION_NO_CONTROLLERand EXCEPTION_NO_ACTION)

I realized that this means that I have to get rid of the default actions /: module /: controller /: action and /: controller /: action.

Therefore, when I tell the router removeDefaultRoutes (), it will no longer match these default routes. But now the router now routes every unused route to defaultcontroller :: defaultaction (What the ??)

$front->getRouter()->removeDefaultRoutes();

So, does anyone know how to make the frontcontroller (or part of it) throw an exception when the URI cannot be routed?

The reason I want to do this is to prevent duplication of content and have more than 404 pages (in this case, no control / lack of action errors are actually application errors, not found)

+5
source share
2 answers

,

$route = new Zend_Controller_Router_Route('*', array('controller'=>'error', 'module'=>'default', 'action'=>'error'));


$router->addRoute('default', $route);

, .

+5

... ( )

, , , "". , , , , 404 .

class Application_Plugin_DisableDefaultRoutes extends Zend_Controller_Plugin_Abstract
{
    public function routeShutdown(Zend_Controller_Request_Abstract $request)
    {
        $front = Zend_Controller_Front::getInstance();
        $currentRoute = $front->getRouter()->getCurrentRouteName();
        if ($currentRoute == 'default') {
            throw new Exception('Default route is disabled');
        }
    }
}

Bootstrap.php

protected function _initPlugins()
{
    $front = Zend_Controller_Front::getInstance();
    $front->registerPlugin(new Application_Plugin_DisableDefaultRoutes());
}

, - .

+2

All Articles