Note that there are some explanatory texts on larger screens.

plurals
  1. POZF1 dispatch error controller from bootstrap
    primarykey
    data
    text
    <p>In my Zend Framework 1 project I am trying to add an init to Bootstrap.php that will load some configuration values and then catch an exception if the configuration value doesn't exist. After it catches an exception I want it to route to the error controller and display the error message from the exception that it caught.</p> <p>Is there a way to throw an exception in Bootstrap.php in a Zend Framework 1 project and have the error handler handle it as it would if the exception was thrown from within a controller?</p> <p><strong>Update:</strong> Thanks to <strong>David Weinraub</strong> I came up with the following solution.</p> <p>Bootstrap.php:</p> <pre><code>protected function _initRegistry() { $options = $this-&gt;getOptions(); $fc = Zend_Controller_Front::getInstance(); $fc-&gt;registerPlugin(new Application_Plugin_RegistryHandler($options)); } </code></pre> <p>RegistryHandler.php:</p> <pre><code>use Application\Service\Config\Config; use Application\Service\Config\MailConfig; /** * Handles the loading of objects and values into the registry, we use a plugin * so exceptions can be thrown and caught with * Zend_Controller_Plugin_ErrorHandler. */ class Application_Plugin_RegistryHandler extends Zend_Controller_Plugin_Abstract { /** * @var array */ private $options; /** * @param array $options */ public function __construct($options) { $this-&gt;options = $options; } /** * Load the config classes into registry on route startup * so the error controller should be loaded and ready to catch exceptions. * * @param Zend_Controller_Request_Abstract $request */ public function routeStartup(Zend_Controller_Request_Abstract $request) { $registry = Zend_Registry::getInstance(); $mailConfig = new MailConfig($this-&gt;options); $config = new Config($this-&gt;options); $config-&gt;setMailConfig($mailConfig); $registry-&gt;set('config', $config); } } </code></pre> <p>Any exceptions thrown from here are caught and handled with the error handler and can display a nice message like "Configuration value 'doctrine.conn.database' is missing from local.ini", I then use the registry to access these configuration values (entity manager and mail handler to be added later) from anywhere in the application.</p> <p>I wish I had the authority to move this project to Zend Framework 2, much easier to work with.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload