symfony 1.4: How to pass exception message to error.html.php?

前端 未结 3 1833
情歌与酒
情歌与酒 2020-12-30 16:13

I tried using special variable $message described here http://www.symfony-project.org/cookbook/1_2/en/error_templates but it seems this variable isn\'t defined

3条回答
  •  一生所求
    2020-12-30 16:47

    I've found another trick to do that - sfContext can be used to pass exception message to error.html.php but custom function have to be used to throw exception. For example:

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

    than insted of using throw new sfException('some message') you should use myToolkit::throwException('some message')

    To display message in error.html.php use get('error_msg') ?>

提交回复
热议问题