Symfony 1.4: How to pass error.html.php error message?

I tried to use the special variable $messagedescribed here http://www.symfony-project.org/cookbook/1_2/en/error_templates , but it looks like this variable is not defined in symfony 1.4, at least it does not contain the messages transmitted in exception in this waythrow new sfException('some message')

Do you know another way to pass this error.html.php message?

+5
source share
3 answers

You will need to perform incorrect error handling. We ourselves have contributed to Symfony’s own action. Be careful, although this action may also throw an exception, you should take this into account.

The following may be a good start. Add a listener for the event first, a good place would be ProjectConfiguration.class.php:

$this->dispatcher->connect('application.throw_exception', array('MyClass', 'handleException'));

Using an event handler may be sufficient for what you want to do with an exception, for example, if you just want to send a stack trace to the administrator. We wanted to move on to a custom action to display and process the feedback form. Our event handler looked something like this:

class MyClass {
  public static function handleException(sfEvent $event) {
    $moduleName = sfConfig::get('sf_error_500_module', 'error');
    $actionName = sfConfig::get('sf_error_500_action', 'error500');
    sfContext::getInstance()->getRequest()->addRequestParameters(array('exception' => $event->getSubject()));
    $event->setReturnValue(true);
    sfContext::getInstance()->getController()->forward($moduleName, $actionName);
  }
}

Now you can configure the module and action to forward to the exception in settings.yml

all:
  .actions:
    error_500_module:       error
    error_500_action:       error500

, , , . , . , $request- > getParameter ('exception')

+7

, . Symfony 1.4 $message , $exception ( ).

, echo $exception->message.

Et voilà!

+1

, - sfContext error.html.php, . :

class myToolkit {
  public static function throwException($message) 
    {
      sfContext::getInstance()->set('error_msg', $message);
      throw new sfException($message);
    }

throw new sfException('some message'), myToolkit::throwException('some message')

error.html.php, <?php echo sfContext::getInstance()->get('error_msg') ?>

0
source

All Articles