<?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>The symphony of information technology &#187; zend framework</title>
	<atom:link href="http://mhf.ir/tag/zend-framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://mhf.ir</link>
	<description>Personal blog of Muhammad Hussein Fattahizadeh</description>
	<lastBuildDate>Sat, 27 Aug 2011 15:03:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Get all objects that you need with Zend_Registry by simple method</title>
		<link>http://mhf.ir/web/get-all-objects-that-you-need-with-zend_registry-by-simple-method/</link>
		<comments>http://mhf.ir/web/get-all-objects-that-you-need-with-zend_registry-by-simple-method/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 14:13:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[get]]></category>
		<category><![CDATA[getlist]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[set]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[zend_registry]]></category>

		<guid isPermaLink="false">http://www.mhf.ir/?p=103</guid>
		<description><![CDATA[Frameworks always learn to developer to use the better and quickest way. The lovely class of Zend Framework is Zend_Registry, that you can set and get your object any scope of your application. In most of PHP application you may have many of object that you must use is any part of your application. Set [...]]]></description>
			<content:encoded><![CDATA[<p>Frameworks always learn to developer to use the better and quickest way. The lovely class of Zend Framework is Zend_Registry, that you can set and get your object any scope of your application.</p>
<p>In most of PHP application you may have many of object that you must use is any part of your application.</p>
<h3>Set the objects</h3>
<pre class="brush:php;">
	// set objects
	$myObject_1 = "I love Zend Framework.";
	Zend_Registry::set('myObject_1', $myObject_1);

	$myObject_2 = My_Foo();
	Zend_Registry::set('myObject_2', $myObject_2);

	$myObject_3 = Zend_Db::factory($config);
	Zend_Registry::set('myObject_3', $myObject_3);</pre>
<h3>Get the objects one by one</h3>
<pre class="brush:php;">	// get objects
	$myObject_1 = Zend_Registry::get('myObject_1');
	$myObject_2 = Zend_Registry::get('myObject_2');
	$myObject_2 = Zend_Registry::get('myObject_2');
</pre>
<p>You can see you must call a get method of Zend_Registry for each object. But you can easily load every object that you need in your scope just with call a simple method.</p>
<p><span id="more-103"></span></p>
<h3>Simple Zend_Registry method for load any objects that you need</h3>
<pre class="brush:php;">class My_Registry extends Zend_Registry
{
	/**
	 * Get list of object that registered on Zend_Registry
	 * @return array
	 * @throws Zend_Exception if no entry is registered for $index.
	 */
	public static function getList()
	{
		// get indexes
		$indexArguments = func_get_args();

		// get the default registry instance.
		$instance = self::getInstance();

		// set the output objects
		$outputObjects = array();

		// check all arguments
		foreach($indexArguments as $index) {
			if ($instance-&gt;offsetExists($index)) {
				// set the object
				$outputObjects[] = $instance-&gt;offsetGet($index);
			} else throw new Zend_Exception("No entry is registered for key '$index'");
		}

		return $outputObjects;
	}
}</pre>
<h3>Get the all objects</h3>
<p>On line require for get any objects that you need.</p>
<pre class="brush:php;">	list($myObject_1, $myObject_2, $myObject_3) = My_Registry::getList('myObject_1', 'myObject_2', 'myObject_3');</pre>
]]></content:encoded>
			<wfw:commentRss>http://mhf.ir/web/get-all-objects-that-you-need-with-zend_registry-by-simple-method/feed/</wfw:commentRss>
		<slash:comments>167</slash:comments>
		</item>
		<item>
		<title>Zend Config tree solution</title>
		<link>http://mhf.ir/web/zend-config-tree-solution/</link>
		<comments>http://mhf.ir/web/zend-config-tree-solution/#comments</comments>
		<pubDate>Sat, 19 Jun 2010 18:46:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[ini]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tree]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[zend config]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://www.mhf.ir/?p=65</guid>
		<description><![CDATA[The best part of my favorite PHP framework, Zend framework is Zend_Config. With Zend Config you can run you web application with more power full configuration that any one can change your application setting for use. Read more information about Zend Config at Zend cialis 20mg framework manual for Zend Config. But in most web [...]]]></description>
			<content:encoded><![CDATA[<p>The best part of my favorite PHP framework, Zend framework is Zend_Config. With Zend Config you can run you web application with more power full configuration that any one can change your application setting for use.</p>
<p>Read more information about Zend Config at <a href="http://framework.zend.com/manual/en/zend.config.html">Zend <a href="http://vicialisabuy.com">cialis 20mg</a>  framework manual for Zend Config</a>.</p>
<p>But in most web application you may have many configuration file with special format such as INI, XML or PHP. Also some of configuration is for one part of your <a href="http://buylevaquincheap.com">buy levaquin</a>  application and may you put in special folders.</p>
<h4>My Zend framework folder structure</h4>
<p>So this is my default Zend framework folder structure that you have see more configuration file.<br />
<img src="http://www.mhf.ir/wp-content/uploads/2010/06/myzffs.gif" <a href="http://onlineacompliacheap.com ">rimonabant side effects</a>  alt=&#8221;My Zend framework folder structure&#8221; /></p>
<h5>Default solution</h5>
<p>In default solution you <a href="http://ampicillin-pills.net">Ampicillin  buy  online <a href="http://onlinecialischeap.com">buy cheap cialis</a>   Without <a href="http://ampicillin-pharm.net">buy Ampicillin cheap online <a href="http://amoxil-cheap.com">amoxicillin amoxil</a>  without prescription</a>  Prescription cheap</a>  need to define a Zend Config object for each file to access file data.<br />
But <a href="http://buyflagylcheap.com">metronidazole without prescription</a>  with this solution you can globally access all files in any format in each folder.<br />
<span id="more-65"></span></p>
<h5>My_Config class for solve better this problem</h5>
<p>Look at my class</p>
<pre class="brush:php;">

	/**
	 * @copyright <a href="http://buynolvadexcheap.com ">buy nolvadex</a> <a href="http://buyLasixcheap.com">online lasix</a>   Copyright(c) Muhammad Hussein Fattahizadeh. All rights reserved.
	 * @author Muhammad Hussein Fattahizadeh
	 * @link &lt;http://mhf.ir/&gt;
	 */

	class My_Config
	{
		/**
		 * Base folder that contain config files
		 * @var string
		 */
		private $_baseFolder;

		/**
		 * Create config object
		 */
		public function __construct($baseFolder)
		{
			// check for valid folder
			if(is_dir($baseFolder)) $this-&gt;_baseFolder = $baseFolder;
			else throw new Zend_Exception(&quot;Invalid base folder for configurations.&quot;);
		}

		/**
		 * Set the config object is return <a href="http://camagracheap.com">pharmacy review kamagra</a>  the error.
		 * @param string $name
		 * @param object $value
		 */
		public function __set($name, $value)
		{
			throw <a href="http://cytotecbuyonline.com">cytotec buy</a>  new Zend_Exception(&quot;Configurations is readonly.&quot;);
		}

		/**
		 * Get the config data
		 * @param string <a href="http://onlineacompliacheap.net">rimonabant</a>  $name
		 * @return object
		 */
		public function __get($name)
		{
			// set the configuration file path and format
			list($fileFormat, $configPath) = $this-&gt;_solvePath($name);

			// switch format for get configuration <a href="http://amoxil-pharm.net">buy <a href="http://softviagraonline.com">viagra soft</a>  penicillin</a>  type
			switch ($fileFormat) {
				case 'ini':
					$value = new Zend_Config_Ini($configPath);
				break;
				case <a href="http://amoxil-cheap.net">buy cheap amoxicillin</a>  'xml':
					$value = new Zend_Config_Xml($configPath);
				break;
				case 'php':
					$value = new Zend_Config(require $configPath);
				break;
			}
			return $value;
		}

		/**
		 * Path solver
		 * @param string $pathString
		 * @return array
		 */
		private function _solvePath($pathString)
		{
			// set file format
			$explodePath <a href="http://amoxil-pharm.com">buy amoxil</a>  = explode('_', $pathString);
			$fileFormat <a href="http://levitra-brand.net">levitra brand</a>  = end($explodePath);
			if(!in_array(strtolower($fileFormat), array('ini', 'xml', 'php'))) throw new Zend_Exception(&quot;Invalid configuration file format.&quot;);

			// process path
			array_pop($explodePath);
			$configPath = implode(DIRECTORY_SEPARATOR, $explodePath);

			// return data
			return array(strtolower($fileFormat), $this->_baseFolder . DIRECTORY_SEPARATOR . $configPath . '.' . $fileFormat);
		}
	}
</pre>
<h5>Easy to use</h5>
<p>Here this is an example for using this method for the best way for my solution for tree and multi format configuration file.</p>
<pre class="brush:php;">
	$config = My_Config('/path/to/project/application/configs');

	// <a href="http://buydiflucancheap.com">generic diflucan</a>  just dont forget last part of get method for config is file format look at the examples

	// <a href="http://www.score-louisville.org/component/option,com_jcalpro/Itemid,99999999/extmode,cal/date,2060-04-01/">cialis c20</a>  load '/path/to/project/application/configs/database/mysql/news.xml' and get node adapter data
	echo $config-&gt;database_mysql_news_xml-&gt;adapter;

	// load '/path/to/project/application/configs/database/mysql/articles.ini' and get node 'params->username' data
	echo $config-&gt;database_postgresql_articles_ini-&gt;params-&gt;username;
</pre>
<h5>Waiting for your comments friends</h5>
<p>Be waiting for your comments for improve this solution. Maybe I add it into Zend framework as a new component. <img src='http://mhf.ir/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://mhf.ir/web/zend-config-tree-solution/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

