<?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>Init &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/init/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>Models in Zend Framework &#8211; Initialize All Methods with init()</title>
		<link>/2010/08/09/models-in-zend-framework-initialize-all-methods-with-init/</link>
		<comments>/2010/08/09/models-in-zend-framework-initialize-all-methods-with-init/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 19:05:05 +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[controller]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[given controller]]></category>
		<category><![CDATA[Init]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[Web application frameworks]]></category>

		<guid isPermaLink="false">/?p=1890</guid>
		<description><![CDATA[In the Zend Framework&#8217;s documentation there are lots of examples how you can initialize all the actions in a given controller &#8211; by simply adding the init() public method in the controller&#8217;s code:<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/08/06/setting-up-zend-framework-with-modules/" rel="bookmark" title="Setting Up Zend Framework with Modules">Setting Up Zend Framework with Modules </a></li>
<li><a href="/2010/06/23/bind-zend-action-with-non-default-view-part-2/" rel="bookmark" title="Bind Zend Action with Non-Default View &#8211; Part 2">Bind Zend Action with Non-Default View &#8211; Part 2 </a></li>
<li><a href="/2010/07/07/default-error-handling-in-zend-framework/" rel="bookmark" title="Default Error Handling in Zend Framework">Default Error Handling in Zend Framework </a></li>
<li><a href="/2010/07/06/zend-framework-simple-acl-front-controller-plugin/" rel="bookmark" title="Zend Framework: Simple Acl Front Controller Plugin">Zend Framework: Simple Acl Front Controller Plugin </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>In the Zend Framework&#8217;s documentation there are lots of examples how you can initialize all the actions in a given controller &#8211; by simply adding the init() public method in the controller&#8217;s code:</p>
<pre lang="php">
<?php

class IndexController extends Zend_Controller_Action
{
	public function init()
	{
		echo 'foo';	
	}	
	
	public function indexAction()
	{
		// first the 'foo' string will be printed
		echo 'bar';	
	}
}
</pre>
<p>But did you know that you can do the same thing with any model in ZF? However you can setup a cache for every method or something else, but definitely it will execute for every method:</p>
<pre lang="php">
<?php

class MyModel
{
	public function init()
	{
		// prepare the cache setup
	}	
	
	public function readAll()
	{
		// the cache is already setup
		$sql = '...';
		// ...
	}
}
</pre>
<p>Of course that means that directly calling the readAll() function the init() method is called also - automatically.</p>
<h2>Conclusion</h2>
<p>There are good and bad parts about this. You'll have this code executed for every method and if you have twenty of them and the init() method is practically used for only a couple of the member functions - than this will be useless.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/08/06/setting-up-zend-framework-with-modules/" rel="bookmark" title="Setting Up Zend Framework with Modules">Setting Up Zend Framework with Modules </a></li>
<li><a href="/2010/06/23/bind-zend-action-with-non-default-view-part-2/" rel="bookmark" title="Bind Zend Action with Non-Default View &#8211; Part 2">Bind Zend Action with Non-Default View &#8211; Part 2 </a></li>
<li><a href="/2010/07/07/default-error-handling-in-zend-framework/" rel="bookmark" title="Default Error Handling in Zend Framework">Default Error Handling in Zend Framework </a></li>
<li><a href="/2010/07/06/zend-framework-simple-acl-front-controller-plugin/" rel="bookmark" title="Zend Framework: Simple Acl Front Controller Plugin">Zend Framework: Simple Acl Front Controller Plugin </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/08/09/models-in-zend-framework-initialize-all-methods-with-init/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
