What is the correct way to pass data between plugins and the application as a whole?
In Zend Framework, Controller plugins are common for instantiating and configuring resources that every page will need. For example, I am writing a plugin that encapsulates my authorization methods, using Zend_Auth. How shoul开发者_如何学Cd my plugin "report", or pass data to, other parts of my application? I'm assuming I should use Zend_Registry
...
Since Zend_Registry::set()
and Zend_Registry::get()
create dependencies that are hidden, hard to debug, and hard to unit test, I try to avoid them where I can.
Typically, a plugin can modify the $request
object that it has been passed. The controller can then pull what it needs from the $request
object, passing along whatever it needs into services, models, views, etc.
What I did in one of my project with the same problem was to redirect to the error page if the user didn't have access to the page he asked.
The problem was then to give to the error page the error description and exception and all, in the same format than ZF does internally (you know in your ErrorController you have access to error informations).
What I did was go into ZF code and look how was formatted the data (arrays and classes, but nothing too complicated) and feed our informations to the ErrorController the same way.
The idea was to add the error informations as a request parameter, see below how it was done for the standard ErrorController taking informations from the ErrorHandler plugin.
Standard ErrorController from ZF documentation :
class ErrorController extends Zend_Controller_Action
{
public function errorAction()
{
$errors = $this->_getParam('error_handler');
switch ($errors->type) {
[...]
}
}
}
I don't have the code to help you more about that, but that's a lead that I know works.
精彩评论