Unlike the view and the controller components, the model component can vary dramatically in responsibilities and data storage from one MVC application to the next. It should represent what your application does in the abstract. The Zend Framework community has not defined a model interface, class, or other formalism because we haven't identified enough added value to justify limitations on what constitutes a model.
How can I retrieve the view object within a plugin or arbitrary code?
ZF uses an action helper called the ViewRenderer by default. This action helper instantiates and stores a Zend_View object, which is subsequently injected into other objects. The view object is stored in the ViewRenderer's view property. You can get the ViewRenderer instance, and thereby the view instance, with the Action Helper broker:
However, if you're accessing the view early in the dispatch process- before an action is actually dispatched, for example- then you may need to initialize the view first:
If you are using and have already initialized Zend_Layout, you can access the view object much more succinctly:
This proxies to the ViewRenderer and performs all of the steps above for you.
I'm using the ContextSwitch or AjaxContext view helper and receiving an exception indicating the error.ajax.phtml view script is missing; what am I doing wrong?"
ContextSwitch makes the assumptions that (a) you are not calling _forward() and (b) that your application code will not throw an exception. If you see the above error, your code is throwing an exception - but the context is still in play, and the ViewRenderer is simply trying to load a view script for the current context from the ErrorController.
The easiest way to fix the situation is to have the ErrorController::errorAction() redefine the view script suffix, as follows:
I'm using Apache, and passing urlencoded slashes via $_GET or as URL parameters – and I'm getting 404s!
Apache by default disallows urlencoded slashes (i.e., "%2F") in URL path parts or the query string. This feature can be disabled by enabling the "AllowEncodedSlashes" directive:
However, this directive must be set at either a server-wide (httpd.conf) or virtual-host level.