Jon Skarpeteig
Jon Skarpeteig

Reputation: 4128

Zend ErrorController access initial controller variables

I have an error controller where I send an email on unhandled exceptions. I want to output some variable values which reside in the 'original' controller (E.G indexController).

How can I access these values from the ErrorController? E.G $indexController->attr

Upvotes: 0

Views: 163

Answers (2)

David
David

Reputation: 1312

Well, you can access the original controller action's view variables from your error controller's view object. You could send the required values as view variables (if possible), and then, use them in your error controller:

// In your original controller's action
$this->view->customVariable1 = 123;
$this->view->customVariable2 = 'abc';

// In your error controller's error action
$cv1 = $this->view->customVariable1;
$cv2 = $this->view->customVariable2;

I can say this works, because I've tested displaying my view variables in error.phtml, and it displays the original controller's view variables.

Now, if you need more control, you could use your session to store these values.

Upvotes: 1

faken
faken

Reputation: 6852

I don't think that's possible, because the original controller object is destroyed after the corresponding action has been dispatched (line 314 of Zend_Controller_Dispatcher_Standard, ZF 11.7).

However, if you catch exceptions inside your controllers, you could then push the variables in question to a global registry (e.g. Zend_Registry), and then rethrow the exception in order for it to be caught by the error controller; once the error controller executes, it can access these variables from the global registry.

Upvotes: 0

Related Questions