<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Nilesh&#039;s Blogs</title>
	<atom:link href="http://techhadda.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://techhadda.wordpress.com</link>
	<description>Open source wave</description>
	<lastBuildDate>Sat, 04 Sep 2010 09:05:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='techhadda.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/b077cf2f724f5f8cf7a269421528b4bd?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Nilesh&#039;s Blogs</title>
		<link>http://techhadda.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://techhadda.wordpress.com/osd.xml" title="Nilesh&#039;s Blogs" />
	<atom:link rel='hub' href='http://techhadda.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Working with Zend_db</title>
		<link>http://techhadda.wordpress.com/2010/09/04/working-with-zend_db/</link>
		<comments>http://techhadda.wordpress.com/2010/09/04/working-with-zend_db/#comments</comments>
		<pubDate>Sat, 04 Sep 2010 07:23:21 +0000</pubDate>
		<dc:creator>nileshkulkarni</dc:creator>
				<category><![CDATA[database using Zend_db]]></category>
		<category><![CDATA[Zend_db]]></category>

		<guid isPermaLink="false">http://techhadda.wordpress.com/?p=23</guid>
		<description><![CDATA[Recently worked on project which involved working with Zend_db.  Zend provides good support for interacting with database. Here is how we can use Zend_db to interact with database. 1. Database Configuration Setup First lets set up our database configuration in config.ini (or the settings file for the particular project) db.adapter = PDO_MYSQL db.params.host = localhost [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techhadda.wordpress.com&amp;blog=10638049&amp;post=23&amp;subd=techhadda&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently worked on project which involved working with Zend_db.  Zend provides good support for interacting with database.</p>
<p>Here is how we can use Zend_db to interact with database.</p>
<p><strong>1. Database Configuration Setup</strong></p>
<p>First lets set up our database configuration in config.ini (or the settings file for the particular project)</p>
<p><strong>db.adapter = PDO_MYSQL</strong></p>
<p><strong> db.params.host = localhost<br />
db.params.username = root<br />
db.params.password =<br />
db.params.dbname = sample_db</strong></p>
<p>The above configuration is very simple specifying host, username, password and database name</p>
<p><strong>2. Initiating Database configuration</strong></p>
<p>Now lets load up this configuration. There are different ways we can load it like loading it just before using it in <strong><em>database files (model classes)</em></strong> or using <strong>connection manager files</strong> or load it using <strong><em>Bootstrap</em></strong> file</p>
<p>I prefer it using Bootstrap file. Lets write a function in Bootstrap.php file to load up the database configuration</p>
<p>public static function setupDatabase(){<br />
$config   = new Zend_Config_Ini(&#8216;/conf/config.ini&#8217;,'development&#8217;);<br />
$db          = Zend_Db::factory($config-&gt;db);<br />
Zend_Registry::set(&#8216;databaseConfig&#8217;, $db);<br />
Zend_Db_Table::setDefaultAdapter($db);<br />
}</p>
<p>The above function reads the config.ini file using Zend_Config_Ini class.</p>
<p>Then we assign database configurations to $db and then save it into Zend_Registry so later on we can retrieve it. And lastly set up default adapter for Zend_Table</p>
<p><strong>3. Model Classes</strong></p>
<p>Lets prepare a model class say Profile which will map to profile table with the database</p>
<p>class Profile  extends Zend_Db_Table {<br />
protected $_name = &#8220;profile&#8221;;</p>
<p>protected $_referenceMap    = array(<br />
&#8216;Users&#8217; =&gt; array(<br />
&#8216;columns&#8217;           =&gt; &#8216;userId&#8217;,<br />
&#8216;refTableClass&#8217;     =&gt; &#8216;Users&#8217;,<br />
&#8216;refColumns&#8217;        =&gt; &#8216;id&#8217;<br />
)<br />
);</p>
<p>protected $db        = NULL;</p>
<p>public function __construct(){<br />
$this-&gt;db             = Zend_Db::factory($this-&gt;config-&gt;db);<br />
parent::__construct();<br />
}</p>
<p>}</p>
<p>Lets see what the above code does</p>
<p>We give name to our table called as &#8216;profile&#8217;</p>
<p>Reference map is used to establish relationship with other tables, here we have done it with Users table where userid field will refer to id field in User table</p>
<p>And lastly within the constructor of the model class we are loading up the database configuration which we had setup in our Bootstrap file initially.</p>
<p><strong>4. Model classes with queries</strong></p>
<p>Now lets add up functions which will interact with database and get us back the results</p>
<p>First lets write simple select query which will fetch profile record for a particular userId</p>
<p>public function getProfile($userId){<br />
try{<br />
$this-&gt;config         = Zend_Registry::get(&#8216;config&#8217;);<br />
$query                     = $this-&gt;db-&gt;select()<br />
-&gt;from(array(&#8216;p&#8217;=&gt;&#8217;profile&#8217;))<br />
-&gt;where(&#8216;p.userId = ?&#8217;,$userId);<br />
$data                         = $this-&gt;db-&gt;fetchAll($query);</p>
<p>if(count($data)==1){<br />
return $data;<br />
}<br />
}<br />
catch(Exception $e){<br />
}<br />
return false;<br />
}</p>
<p>Lets look at the query part</p>
<p>We provide which type of query we want to fire (in our case select by specifying $this-&gt;db-&gt;select())</p>
<p>Then we specify the table from which we want to fetch the data and prepare the alias  alias (p =&gt; Profile)</p>
<p>And lastly we specify the where condition.</p>
<p>The above query will return the profile row with matching userId</p>
<p>Now lets write up the query which will get the data using joins</p>
<p>(writing up the query part only rest of the code remains the same)</p>
<p>$query    = $this-&gt;db-&gt;select()<br />
-&gt;from(array(&#8216;p&#8217;=&gt;&#8217;profile&#8217;))<br />
-&gt;joinInner(array(&#8216;u&#8217;=&gt;&#8217;users&#8217;),&#8217;p.userId = u.id&#8217;,array(&#8216;username&#8217;,'image&#8217;))</p>
<p>we can join the tables using joinInner function which requires the table name with which we want to join the data, then we specify the join condition and finally the fields from the other table (in our case we specify only username, image as fields to be shown from user table)</p>
<p>That&#8217;s all we require to interact with database using Zend_db</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/techhadda.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/techhadda.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/techhadda.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/techhadda.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/techhadda.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/techhadda.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/techhadda.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/techhadda.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/techhadda.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/techhadda.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/techhadda.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/techhadda.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/techhadda.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/techhadda.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techhadda.wordpress.com&amp;blog=10638049&amp;post=23&amp;subd=techhadda&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://techhadda.wordpress.com/2010/09/04/working-with-zend_db/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/756ddcdafb1d88df2aca01170cf1251c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nileshkulkarni</media:title>
		</media:content>
	</item>
		<item>
		<title>Introduction to &#8216;Controllers&#8217; in Zend Framework</title>
		<link>http://techhadda.wordpress.com/2009/12/08/introduction-to-controllers-in-zend-framework/</link>
		<comments>http://techhadda.wordpress.com/2009/12/08/introduction-to-controllers-in-zend-framework/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 14:50:28 +0000</pubDate>
		<dc:creator>nileshkulkarni</dc:creator>
				<category><![CDATA[controller]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[actions]]></category>
		<category><![CDATA[introduction to controllers]]></category>
		<category><![CDATA[zend. controllers]]></category>

		<guid isPermaLink="false">http://techhadda.wordpress.com/?p=3</guid>
		<description><![CDATA[Zend_Controller forms heart of Zend frameworks MVC system. Zend_Controller_Front implements a Front Controller pattern. Front controller serves as a launch point for zend MVC application. The front controller&#8217;s responsibility is to accept input from web request, identify and execute specific controller action. Front controller has the responsibility to initialize MVC framework (that includes creating router [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techhadda.wordpress.com&amp;blog=10638049&amp;post=3&amp;subd=techhadda&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Zend_Controller forms heart of Zend frameworks MVC system.</p>
<p>Zend_Controller_Front implements a Front Controller pattern. Front controller serves as a launch point for zend MVC application. The front controller&#8217;s responsibility is to accept input from web request,<br />
identify and execute specific controller action.</p>
<p>Front controller has the responsibility to initialize MVC framework (that includes creating router and dispatcher) and creating proper request object. Front controller is implemented as singleton pattern which means only one instance of it throughout the application and it can be referenced from anywhere in the system.</p>
<p>Outcome of front controller execution is creation of instances of router and dispatcher and pass execution control of request to request for further processing.</p>
<p>Once router has received request object its responsibility is to examine received data and determine which controller and action to execute. Router recognizes the controller and action by mapping the url with help<br />
of default router. Of course this is completely customizable i.e. we can create our own custom routers and map it to controller and action. Note if no router is provided Zend framework by default maps to &#8220;index&#8221; controller and its &#8220;index&#8221; action.</p>
<p>Once the mapping is done the request object is passed to dispatcher which dispatches to an action within the controller. The job of dispatcher is to execute the business logic by executing action depending on the<br />
routing information provided by router.</p>
<p>For every action that is executed following steps are executed<br />
1. Initialization of controller class<br />
2. Call to init method<br />
3. Call to preDispatch method<br />
4. Execution of requested action.<br />
5. Call to postDispatch method</p>
<p>In the simplest implementation of controller only action needs to be implemented.</p>
<p>Controllers are named in the form of TestController, where name of controller is Test followed by Controller suffix.</p>
<p>Actions are named in the form of testAction where action name is &#8220;test&#8221; followed by Action suffix.</p>
<p>A typical controller will look like</p>
<p>class TestController extends Zend_Controller_Action {</p>
<p>function init(){</p>
<p>// initialization code</p>
<p>}</p>
<p>function preDispatch(){</p>
<p>// code to be executed before an action gets called</p>
<p>}</p>
<p>function postDispatch(){</p>
<p>//  code to be executed after an action gets called</p>
<p>}</p>
<p>public function myAction(){</p>
<p>// action code</p>
<p>}</p>
<p>}</p>
<p>Note init, preDispatch and postDispatch methods are optional.</p>
<p>That&#8217;s all on controller section.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/techhadda.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/techhadda.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/techhadda.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/techhadda.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/techhadda.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/techhadda.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/techhadda.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/techhadda.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/techhadda.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/techhadda.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/techhadda.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/techhadda.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/techhadda.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/techhadda.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techhadda.wordpress.com&amp;blog=10638049&amp;post=3&amp;subd=techhadda&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://techhadda.wordpress.com/2009/12/08/introduction-to-controllers-in-zend-framework/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/756ddcdafb1d88df2aca01170cf1251c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nileshkulkarni</media:title>
		</media:content>
	</item>
	</channel>
</rss>
