We have a plugin which has a postDispatch hook used to record usage statistics on a CMS developed using ZF1. After one of the records is generated, we need to get it's unique id to the view to be able to update it via AJAX requests.
Several posts offer different methods for setting view variables from the postDispatch function but none of them have worked for us. They all work on the preDispatch dough.
Method 1 from this answer works on preDispatch but not on postDispatch.
$view = Zend_Controller_Front::getInstance()
->getParam('bootstrap')
->getResource('view');
$view->recordUID = XXXXXX
Same for method 2
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
if (null === $viewRenderer->view) {
$viewRenderer->initView();
}
$view = $viewRenderer->view;
$view->recordUID = XXXXXX
Another user suggested elsewhere (can't find the reference now) to use Zend's registry which also worked on preDispatch but not on postDispatch
Zend_Registry::set('recordUID', 'XXXXXX');
It would seem the view object is lost after the request has been dispatched.
Additional information
- The view is initialized in Bootstrap.php (required for method 1)
- The pluggin is registered in public\index.php
- The the method that registers statistics runs using the postDispatch function