How to handle Zend_Exception in preDispatch or to trigger an action when using the base controller?

As mentioned in the Zend Framework manual , I created a base controller.

Subclassification of action controller

By design, Zend_Controller_Action needs subclasses to create an action controller. At a minimum, you will need to determine the methods of action that the controller may cause.

In addition to creating useful features for your web applications, you may also find that you repeat a lot of the same installation method or utility in your various controllers; if so, creating a common base controller class that extends Zend_Controller_Action can solve such redundancy.

But it turns out that Exceptions are not properly called from the database ... To replicate this, create a file:

/path/to/workspace/library/Joe/Controller.php

Then:

class Joe_Controller extends Zend_Controller_Action
{
    public function init()
    {
        Throw new Zend_Exception('test', 500);
        parent::init();
    }
}

Then, in your controller directory, IndexController.php exits the database:

class IndexController extends Joe_Controller
{

You will find that the exception is not shown.

If, however, you do not extend the base controller and then throw an exception in init or preDispatch, it will be caught and redirected to ErrorController.

Does anyone have an idea to get exceptions found on the base controller?

Thank.

UPDATE TO REDUCE THIS OTHER WAY

, , /Joe/... , , ... , . ?

, , , , :

Joe_Controller_Action Zend_Controller_Action.

, ...

, , , , , ​​Zend Framework?

, Zend_Exception init preDispatch. , ( , )... . . , - .

, ... Zend_Application, ZF 1.5.

+3
3

:

  • SomethingController. Joe_Controller Joe .

  • /, ? , , ControllerNotFound?

.

0

Zend, init(),

public class Module_TotoController extends Zend_Action_Controller {

    public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array())
        parent::__construct($request, $response, invokeArgs);

        // some init code here
    }
}

:

public class Module_TotoController extends Zend_Action_Controller {

    public function init ()
        // some init code here
    }
}

, Zend_Controller_Action, , : empty:

  • init()
  • preDispatch ()
  • postDispatch ()

, parent::

public class Module_TotoController extends Zend_Action_Controller {

    public function init ()
        parent::init(); // useless ;-) but you can go for it 

        // some init code here
    }
}

, Module_TotoController Zend_Action_Controller, :

  • "" (, ErrorController )
    • , ?
  • init() "",
    • parent:: init(),
  • -
    • / , -
      • ?
        • : $this->_helper->connect();?
        • :
  • "" ,

,

0

- .

:

Zend_Controller_Action , .

,

class Module_TotoController extends Zend_Controller_Action {}

class Module_TotoController extends Joe_Controller (, )

, ErrorController Joe_Controller ErrorController ( !!!)

uncaught Exception , (dig Zend\Controller\Plugin\ErrorHanlder.php line 200-ish)

- , Zend_Controller_Plugin frontController

-1

Source: https://habr.com/ru/post/1766118/


All Articles