<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>zend view renderer &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/zend-view-renderer/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>Bind Zend Action with Non-Default View &#8211; Part 2</title>
		<link>/2010/06/23/bind-zend-action-with-non-default-view-part-2/</link>
		<comments>/2010/06/23/bind-zend-action-with-non-default-view-part-2/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 14:26:41 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[HTML element]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[Web application frameworks]]></category>
		<category><![CDATA[World Wide Web]]></category>
		<category><![CDATA[zend]]></category>
		<category><![CDATA[zend view renderer]]></category>

		<guid isPermaLink="false">/?p=1664</guid>
		<description><![CDATA[Typical Setup Typically Zend Framework is setup to bind every controller&#8217;s action to a specific view. The names of the action and the view script must be the same, or at least must be similar &#8211; following the ZF&#8217;s convention. Thus if you name an action, let&#8217;s say, indexAction(), you&#8217;ve to create an index.phtml file &#8230; <a href="/2010/06/23/bind-zend-action-with-non-default-view-part-2/" class="more-link">Continue reading <span class="screen-reader-text">Bind Zend Action with Non-Default View &#8211; Part 2</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/06/07/bind-zend-action-with-non-default-view/" rel="bookmark" title="Bind Zend Action with Non-Default View">Bind Zend Action with Non-Default View </a></li>
<li><a href="/2010/06/24/zend-framework-inject-javascript-code-in-a-actionview/" rel="bookmark" title="Zend Framework: Inject JavaScript Code in a Action/View">Zend Framework: Inject JavaScript Code in a Action/View </a></li>
<li><a href="/2010/01/29/escaping-strings-in-a-zend-framework-view-prevent-unclosed-tags/" rel="bookmark" title="Escaping strings in a Zend Framework view. Prevent unclosed tags!">Escaping strings in a Zend Framework view. Prevent unclosed tags! </a></li>
<li><a href="/2010/04/27/inline-scripts-with-zend_view_helper_inlinescript/" rel="bookmark" title="Inline Scripts with Zend_View_Helper_InlineScript">Inline Scripts with Zend_View_Helper_InlineScript </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Typical Setup</h2>
<p>Typically <a href="http://framework.zend.com/">Zend Framework</a> is setup to bind every controller&#8217;s action to a specific view. The names of the action and the view script must be the same, or at least must be similar &#8211; following the ZF&#8217;s convention.</p>
<p>Thus if you name an action, let&#8217;s say, indexAction(), you&#8217;ve to create an index.phtml file into the views/scripts/index/ folder. Let me remind you that this is what is called a typical setup, but this may vary from one installation to another.</p>
<p>Thus everything&#8217;s fine and the MVC does its best. After the user requests a specific uri, the framework parses it and finds the controller, than the action and than the view script &#8211; and there is a view script for every single action.</p>
<p><a href="/wp-content/uploads/2010/06/typical-zend-framework-setup.jpg"><img class="alignleft size-medium wp-image-1675" title="typical-zend-framework-setup" src="/wp-content/uploads/2010/06/typical-zend-framework-setup-300x162.jpg" alt="typical zend framework setup" width="300" height="162" srcset="/wp-content/uploads/2010/06/typical-zend-framework-setup-300x162.jpg 300w, /wp-content/uploads/2010/06/typical-zend-framework-setup.jpg 545w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>When there are two or more actions &#8211; there are two or more .phtml (view scripts) files.</p>
<p><a href="/wp-content/uploads/2010/06/typical-zend-framework-setup2.jpg"><img class="alignleft size-medium wp-image-1676" title="typical-zend-framework-setup2" src="/wp-content/uploads/2010/06/typical-zend-framework-setup2-300x203.jpg" alt="typical zend framework setup for two or more actions" width="300" height="203" srcset="/wp-content/uploads/2010/06/typical-zend-framework-setup2-300x203.jpg 300w, /wp-content/uploads/2010/06/typical-zend-framework-setup2.jpg 630w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<h2>Some Exceptions</h2>
<p>Sometimes you have very similar logic, but very different markup between two actions. As the logic goes to the controller/action and the markup into the view, the question is can you simply have one action in the controller, but with two different .phtml file as a view scripts?  Of course switching between those two (or more) with some conditionals.</p>
<h3>Solution No. 1</h3>
<p>However once I posted a simple, and working, <a href="/2010/06/07/bind-zend-action-with-non-default-view/">solution</a>. There you have again two actions and two scripts:</p>
<pre lang="php">
<?php

class IndexController extends Zend_Controller_Action
{	
	public function firstAction()
	{
		// place all the logic you need here
		// and every view placeholder assignment
		$this->view->title = "My Title";
		
		// if the logic requires a different markup
		// simply redirect to another view
		if (some_expression) {
			$this->_forward('second');	
		}	
	}
	
	public function secondAction()
	{}
}

// in the application/views/scripts/index
// 1. first.phtml
<h1><?php echo $this->title ?></h1>

// 2. second.phtml
<h2><?php echo $this->title ?></h2>
</pre>
<p>As you can see in the second action there&#8217;s no logic &#8211; it&#8217;s only serving the role of a bridge between the views. Everything is setup into the first action, but the second action is doing the relation with the second.phtml view script.</p>
<h3>Solution No. 2</h3>
<p>However there&#8217;s another solution with only one action and two scripts which makes something like that shown on the diagram bellow:</p>
<p><a href="/wp-content/uploads/2010/06/zend-framework-one-action-multiple-views.jpg"><img class="alignleft size-medium wp-image-1677" title="zend-framework-one-action-multiple-views" src="/wp-content/uploads/2010/06/zend-framework-one-action-multiple-views-300x203.jpg" alt="zend framework one action multiple=" height="203" srcset="/wp-content/uploads/2010/06/zend-framework-one-action-multiple-views-300x203.jpg 300w, /wp-content/uploads/2010/06/zend-framework-one-action-multiple-views.jpg 630w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>The only thing to do is to add some code to your action:</p>
<pre lang="php">
<?php

class IndexController extends Zend_Controller_Action
{	
	public function firstAction()
	{
		// place all the logic you need here
		// and every view placeholder assignment
		$this->view->title = "My Title";
		
		// if the logic requires a different markup
		// simply redirect to another view
		if (some_expression) {
			echo $this->view->render('index/second.phtml');
			$this->_helper->viewRenderer->setNoRender(true);
		}	
	}
}

// in the application/views/scripts/index
// 1. first.phtml
<h1><?php echo $this->title ?></h1>

// 2. second.phtml
<h2><?php echo $this->title ?></h2>
</pre>
<p>Note that you&#8217;ve to setNoRender on the view renderer once you render the other script!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/06/07/bind-zend-action-with-non-default-view/" rel="bookmark" title="Bind Zend Action with Non-Default View">Bind Zend Action with Non-Default View </a></li>
<li><a href="/2010/06/24/zend-framework-inject-javascript-code-in-a-actionview/" rel="bookmark" title="Zend Framework: Inject JavaScript Code in a Action/View">Zend Framework: Inject JavaScript Code in a Action/View </a></li>
<li><a href="/2010/01/29/escaping-strings-in-a-zend-framework-view-prevent-unclosed-tags/" rel="bookmark" title="Escaping strings in a Zend Framework view. Prevent unclosed tags!">Escaping strings in a Zend Framework view. Prevent unclosed tags! </a></li>
<li><a href="/2010/04/27/inline-scripts-with-zend_view_helper_inlinescript/" rel="bookmark" title="Inline Scripts with Zend_View_Helper_InlineScript">Inline Scripts with Zend_View_Helper_InlineScript </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/06/23/bind-zend-action-with-non-default-view-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
