views:

46

answers:

2

In my app I want to use $this->forward404("Data not found"); to output individual error messages when necessary. In the dev mode it works fine. When I run my app in production mode - where debug is set to false in getApplicationConfiguration() - I don't get the messages anymore.

in settings.yml I set a custom 404 action. all: .actions: error_404_module: main error_404_action: custom404

How can I pass the forward404 to my custom404Success.php template???

+1  A: 

The 404 handling is completely different between prod and dev. In prod, the message you pass to the forward404 is simply written to the log and not passed to the handler action.

There are many ways to get round this, but the quickest (albeit dirtiest) would be to store the message in a static variable somewhere so the 404 handler can access it once the process gets there, e.g.

In your action,

<?php
CommonActions::$message404 = 'My message';
$this->forward404();

And in your 404 handler (assuming it's in CommonActions),

<?php
if (self::$message404) {
    $this->message = self::$message404;
}
Stephen Melrose
+1  A: 

If you are able to get code of method you can see that method throws an sfError404Exception, that handles respect of enviroment. In dev it simple throws an exception and in prod it might be handle via set_exception_handler("my_handle").

You can override this method(it's public)

public function forward404($message = null)
{
  // write to session and call from 404_template via <?php echo $sf_user->getFlash("404message") ?>
  $this->getUser()->setFlash("404message", $message);

  parent::forward404($message);
}
eldar