Logo F2FInterview

Zend Framework Interview Questions

Q   |   QA

When you think that you are getting wrong output from Zend_Date then it's often needed to see what Zend_Date really uses internally.

Well.. a var_dump of Zend_Date is not really helpfull, but you could simply use getIso(). This format has all date informations available:

$date->getIso(); // could return '2009-10-21T15:00:02+01:00'

Note that using toString() and outputting only parts of a date does not show all needed informations. There could be a wrong used timezone, or a DST change which is suppressed by toString() but shown with getIso().

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.

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:

$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer';

$view = $viewRenderer->view;

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 (!isset($viewRenderer->view))




$view = $viewRenderer->view;

If you are using and have already initialized Zend_Layout, you can access the view object much more succinctly:

$view = Zend_Layout::getMvcInstance()->getView();

This proxies to the ViewRenderer and performs all of the steps above for you.

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:

class ErrorController extends Zend_Controller_Action
    public function errorAction()
        // ...

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:

AllowEncodedSlashes On

However, this directive must be set at either a server-wide (httpd.conf) or virtual-host level.

In order to link this F2FInterview's page as Reference on your website or Blog, click on below text area and pres (CTRL-C) to copy the code in clipboard or right click then copy the following lines after that paste into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code: