View Source

<h1>Frequently Encountered Problems</h1>


<h3>A list of frequently encountered problems that occur from simple mistakes or by those who simply &quot;forgot&quot; about what the manual said...</h3>


<hr />
<table><tbody>
<tr>
<th><p> Problem </p></th>
<th><p> Answer </p></th>
</tr>
<tr>
<td><p> Why is it rendering a view when I never told it too? <br class="atl-forced-newline" />
<br class="atl-forced-newline" />
Or: Why am I gettin a&nbsp; &quot;Zend_View_Exception&quot; about a script not being found? <br class="atl-forced-newline" /> </p></td>
<td><p> ViewRenderer was added in RC1 which renders views automatically, based on your controller/action name, have a look at <a href="http://devzone.zend.com/article/2072-Zend-Frameworks-MVC-Introduces-the-ViewRenderer">Zend Framework's MVC Introduces the ViewRenderer</a> and the <a href="http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelper.stockhelpers">the manual on action helpers</a> </p></td>
</tr>
<tr>
<td><p> How do I disable ViewRenderer then? <br class="atl-forced-newline" /> </p></td>
<td><p> Simply set the 'noViewRenderer' controller param which will disable it completely: <br class="atl-forced-newline" /></p>
<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
$front->setParam('noViewRenderer', true); //Assuming $front is your front controller instance
]]></ac:plain-text-body></ac:macro>
<p><br class="atl-forced-newline" />
You can read the ViewRenderer section of the manual for more precise control, see <a href="http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.viewrenderer">ViewRenderer Manual</a> </p></td>
</tr>
<tr>
<td><p> How do I use a common header and footer in my View templates? <br class="atl-forced-newline" /> </p></td>
<td><p> At the moment, the Zend Framework 1.0.0 doesn't have an &quot;officially blessed&quot; solution, so there are multiple approaches being used: <br class="atl-forced-newline" /></p>
<ol>
<li>Front Controller plug-in: <a href="http://www.nabble.com/Controller-and-View-Question-tf3462561.html">Controller and View Question</a></li>
<li>Zend_Layout proposal: <a href="http://framework.zend.com/wiki/display/ZFPROP/Zend_Layout">Zend_Layout</a> (<a href="http://www.spotsec.com/blogs/archive/the-basics-of-zend_layout-ahem-xend_layout.html">Xend Layout tutorial</a>)</li>
<li>Zend_View Enhanced proposal: <a href="http://framework.zend.com/wiki/pages/viewpage.action?pageId=33071">Zend_View_Enhanced</a></li>
<li>Extend ViewRenderer directly: <a href="http://akrabat.com/2007/06/02/extending-viewrenderer-for-layouts/">Extending ViewRenderer</a></li>
<li>If the above fail (or seem too complicated), you can render alternative view scripts from your views: <br class="atl-forced-newline" />
<ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
<?php echo $this->render('index/header.phtml'); ?>
]]></ac:plain-text-body></ac:macro> </li>
</ol>
</td>
</tr>
<tr>
<td><p> Why am I getting an exception with the message 'Invalid controller specified (error)' </p></td>
<td><p> You haven't set up an ErrorController to catch errors. By default the framework has a front controller plugin that tries to send all exceptions to a special controller (ErrorController in the default module). There's a sample error controller, and more information on the plugin, in the <a href="http://framework.zend.com/manual/en/zend.controller.plugins.html#zend.controller.plugins.standard">manual</a> </p></td>
</tr>
<tr>
<td><p> Why am I getting an exception about &quot;error.phtml&quot; was not found? <br class="atl-forced-newline" /> </p></td>
<td><p> This has to deal partly with ViewRenderer rendering view automatically, but more importantly, it occurs because there was an error somewhere and you were redirected to the ErrorController, but error.phtml could not be rendered, generating another error. <br class="atl-forced-newline" /> </p></td>
</tr>
<tr>
<td><p> I'm having problems loading files, getting a &quot;No such file&quot; error. <br class="atl-forced-newline" /> </p></td>
<td><p> <br class="atl-forced-newline" />
&nbsp;You may have one of the following problems: <br class="atl-forced-newline" /></p>
<ul>
<li>You didn't set up your include path right, make sure the library is included. Set it on top of your bootstrap, before any require_once or Zend_Loader::loadClass() statements.</li>
<li>You've specified the library ending in 'Zend' (make sure it's /path/to/your/library, not /path/to/your/library/Zend/)</li>
<li>You're trying to load a model in a &quot;models&quot; directory, without having it set in your include path, have a look at <a href="http://www.spotsec.com/blogs/archive/zend-model-loading-modelloader.html?Itemid=125">Spotsec's model loader</a></li>
</ul>
</td>
</tr>
<tr>
<td><p> How do I create urls like this &quot;/index/about&quot; for Zend Framework? <br class="atl-forced-newline" /> </p></td>
<td><p> Zend Framework has a url view helper and a url action helper to generate urls for you. You can read about them more in this blog article: <a href="http://naneau.nl/2007/07/08/use-the-url-view-helper-please/">Use the url helper please</a> <br class="atl-forced-newline" /> </p></td>
</tr>
<tr>
<td><p> Why doesn't the action &quot;NoRoute&quot; work anymore? (Pre-ZF RC1) <br class="atl-forced-newline" /> </p></td>
<td><p> As of ZF RC1 we now use the <a href="http://framework.zend.com/manual/en/zend.controller.plugins.html#zend.controller.plugins.standard.errorhandler">ErrorHandler controller plugin</a> to handle all errors within the dispatch sequence. <br class="atl-forced-newline" /> </p></td>
</tr>
<tr>
<td><p> How do I integrate Smarty with Zend Framework? <br class="atl-forced-newline" /> </p></td>
<td><p> While it may cause problems and is probably discouraged, there have been many requests on how to do this. Here is one integration article for post RC1 ZF versions: <a href="http://naneau.nl/2007/05/31/using-naneau_view_smarty-with-rc1/">Smarty Integration</a> <br class="atl-forced-newline" /> </p></td>
</tr>
<tr>
<td><p> Why does rendering fail after integrating Smarty and Zend Framework and implementing common layout templates (in a different directory to view templates)?<br class="atl-forced-newline" /> </p></td>
<td><p> Note that Smarty can only handle one template directory (a limitation of Smarty). One work around is to make your View check if the file exists in each of the script paths and then set the template directory appropriately. Note that you'll also need to use {$this-&gt;render('template.tpl')} rather than {include file='template.tpl'} for this to work. Full info on issue and resolution to follow!<br class="atl-forced-newline" /> </p></td>
</tr>
</tbody></table>