<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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: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>Comments on: Zend Framework DAL: DAOs and DataMappers</title>
	<atom:link href="http://blog.fedecarg.com/2009/09/19/zend-framework-dal-daos-and-datamappers/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.fedecarg.com/2009/09/19/zend-framework-dal-daos-and-datamappers/</link>
	<description>Simple is better than complex. Complex is better than complicated. &#124; @fedecarg</description>
	<lastBuildDate>Mon, 06 Feb 2012 14:38:53 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Rasmus</title>
		<link>http://blog.fedecarg.com/2009/09/19/zend-framework-dal-daos-and-datamappers/#comment-7183</link>
		<dc:creator><![CDATA[Rasmus]]></dc:creator>
		<pubDate>Tue, 03 May 2011 06:16:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.fedecarg.com/?p=1713#comment-7183</guid>
		<description><![CDATA[I was looking for good code examples using both DAO and repositories and fell over your site. I don&#039;t use Zend (or PHP for that matter) so excuse me if I have misunderstood something.

You are giving a simple and great overview of the different responsibilities, I did however not like the line: 
 $this-&gt;setDatabaseDao(new UserDatabaseDao());

Here you&#039;re coupling the repository layer directly with the DAO implementation. This is perhaps also what Emran is saying, but on C# I would use some kind of &quot;inversion of control container&quot; for this. Injecting the given implementation into the class through your repository constructor.

If this is not possible in Zend, I would the very least put the instantation of the DAO classes in some factory to keep all the coupling to specific DAO classes in one place.

Thanks for sharing...]]></description>
		<content:encoded><![CDATA[<p>I was looking for good code examples using both DAO and repositories and fell over your site. I don&#8217;t use Zend (or PHP for that matter) so excuse me if I have misunderstood something.</p>
<p>You are giving a simple and great overview of the different responsibilities, I did however not like the line:<br />
 $this-&gt;setDatabaseDao(new UserDatabaseDao());</p>
<p>Here you&#8217;re coupling the repository layer directly with the DAO implementation. This is perhaps also what Emran is saying, but on C# I would use some kind of &#8220;inversion of control container&#8221; for this. Injecting the given implementation into the class through your repository constructor.</p>
<p>If this is not possible in Zend, I would the very least put the instantation of the DAO classes in some factory to keep all the coupling to specific DAO classes in one place.</p>
<p>Thanks for sharing&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: web designer</title>
		<link>http://blog.fedecarg.com/2009/09/19/zend-framework-dal-daos-and-datamappers/#comment-6794</link>
		<dc:creator><![CDATA[web designer]]></dc:creator>
		<pubDate>Tue, 03 Aug 2010 12:09:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.fedecarg.com/?p=1713#comment-6794</guid>
		<description><![CDATA[Very .. usefull information. I rarely use Zend but my reading was very helpful]]></description>
		<content:encoded><![CDATA[<p>Very .. usefull information. I rarely use Zend but my reading was very helpful</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Federico</title>
		<link>http://blog.fedecarg.com/2009/09/19/zend-framework-dal-daos-and-datamappers/#comment-5235</link>
		<dc:creator><![CDATA[Federico]]></dc:creator>
		<pubDate>Mon, 14 Dec 2009 12:06:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.fedecarg.com/?p=1713#comment-5235</guid>
		<description><![CDATA[What I&#039;m doing is passing a Loader (Factory) and Injector to the ORM Manager, who&#039;s responsible for loading the DataMapper and injecting dependencies. I&#039;m not using a Locator class, but you can use one if you want, I guess it depends on the directory structure of your project.]]></description>
		<content:encoded><![CDATA[<p>What I&#8217;m doing is passing a Loader (Factory) and Injector to the ORM Manager, who&#8217;s responsible for loading the DataMapper and injecting dependencies. I&#8217;m not using a Locator class, but you can use one if you want, I guess it depends on the directory structure of your project.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Emran Hasan</title>
		<link>http://blog.fedecarg.com/2009/09/19/zend-framework-dal-daos-and-datamappers/#comment-5225</link>
		<dc:creator><![CDATA[Emran Hasan]]></dc:creator>
		<pubDate>Thu, 10 Dec 2009 16:16:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.fedecarg.com/?p=1713#comment-5225</guid>
		<description><![CDATA[Hi All, 

While implementing this DataMapper pattern in my project, I was thinking that we&#039;re using the DataMappers to abstract away the DAOs from the models - so that we can swap a DAO whenever we need (say for caching). However, we have to keep the interface of the DAOs same so that the mapper can work with it without knowing anything about the implementation details - it just needs to know the functions that are same across all the DAO implementations. 

Now, how about using a Factory to do the same? As the DAOs are implementing the same interface, models need not to know more details about their inner implementation. Consider the following code (written in Project_Model_User:

&lt;code&gt;
$dao = DaoFactory::create(&quot;Db&quot;); 
$dao-&gt;setTable(&quot;users&quot;);
$user = $dao-&gt;find(13);
&lt;/code&gt;

In a similar way, we can do the following, based on logic/settings:

&lt;code&gt;$dao = DaoFactory::create(&quot;ZohoCloudDB&quot;);&lt;/code&gt;
&lt;code&gt;$dao = DaoFactory::create(&quot;MyService&quot;);&lt;/code&gt;

What are the pros/cons of this approach? Any thoughts from anybody? 

Thanks]]></description>
		<content:encoded><![CDATA[<p>Hi All, </p>
<p>While implementing this DataMapper pattern in my project, I was thinking that we&#8217;re using the DataMappers to abstract away the DAOs from the models &#8211; so that we can swap a DAO whenever we need (say for caching). However, we have to keep the interface of the DAOs same so that the mapper can work with it without knowing anything about the implementation details &#8211; it just needs to know the functions that are same across all the DAO implementations. </p>
<p>Now, how about using a Factory to do the same? As the DAOs are implementing the same interface, models need not to know more details about their inner implementation. Consider the following code (written in Project_Model_User:</p>
<p><code><br />
$dao = DaoFactory::create("Db");<br />
$dao-&gt;setTable("users");<br />
$user = $dao-&gt;find(13);<br />
</code></p>
<p>In a similar way, we can do the following, based on logic/settings:</p>
<p><code>$dao = DaoFactory::create("ZohoCloudDB");</code><br />
<code>$dao = DaoFactory::create("MyService");</code></p>
<p>What are the pros/cons of this approach? Any thoughts from anybody? </p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Federico</title>
		<link>http://blog.fedecarg.com/2009/09/19/zend-framework-dal-daos-and-datamappers/#comment-5011</link>
		<dc:creator><![CDATA[Federico]]></dc:creator>
		<pubDate>Fri, 27 Nov 2009 17:22:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.fedecarg.com/?p=1713#comment-5011</guid>
		<description><![CDATA[Yes, a month after I published this post Matthew gave a talk about &quot;Architecting Your Models&quot; http://bit.ly/5dHrzv and the manual was updated.

The idea behind this post was to show how the Data Mapper pattern works independently of the Table Data Gateway pattern.]]></description>
		<content:encoded><![CDATA[<p>Yes, a month after I published this post Matthew gave a talk about &#8220;Architecting Your Models&#8221; <a href="http://bit.ly/5dHrzv" rel="nofollow">http://bit.ly/5dHrzv</a> and the manual was updated.</p>
<p>The idea behind this post was to show how the Data Mapper pattern works independently of the Table Data Gateway pattern.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: phpfour</title>
		<link>http://blog.fedecarg.com/2009/09/19/zend-framework-dal-daos-and-datamappers/#comment-5009</link>
		<dc:creator><![CDATA[phpfour]]></dc:creator>
		<pubDate>Fri, 27 Nov 2009 15:43:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.fedecarg.com/?p=1713#comment-5009</guid>
		<description><![CDATA[Hi Federico,

Thanks for your response and the code examples - things are clearer now. 

I was checking the ZF quick-start tutorial on this URL: http://framework.zend.com/docs/quickstart/create-a-model-and-database-table. It shows an integration between the Domain Entity and the Domain Model. 

Although to my eyes it seems to be pretty much the same, but do you see any foreseeable problem with that approach? Your comment would be appreciated.

Thanks

Emran]]></description>
		<content:encoded><![CDATA[<p>Hi Federico,</p>
<p>Thanks for your response and the code examples &#8211; things are clearer now. </p>
<p>I was checking the ZF quick-start tutorial on this URL: <a href="http://framework.zend.com/docs/quickstart/create-a-model-and-database-table" rel="nofollow">http://framework.zend.com/docs/quickstart/create-a-model-and-database-table</a>. It shows an integration between the Domain Entity and the Domain Model. </p>
<p>Although to my eyes it seems to be pretty much the same, but do you see any foreseeable problem with that approach? Your comment would be appreciated.</p>
<p>Thanks</p>
<p>Emran</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Federico</title>
		<link>http://blog.fedecarg.com/2009/09/19/zend-framework-dal-daos-and-datamappers/#comment-5006</link>
		<dc:creator><![CDATA[Federico]]></dc:creator>
		<pubDate>Fri, 27 Nov 2009 15:02:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.fedecarg.com/?p=1713#comment-5006</guid>
		<description><![CDATA[Hi Emran

Q #1:
http://fedecarg.codepad.org/Uq9ihiSj

Q #2:
http://codepad.org/v8cj85Mk (clone the entity object) 
]]></description>
		<content:encoded><![CDATA[<p>Hi Emran</p>
<p>Q #1:<br />
<a href="http://fedecarg.codepad.org/Uq9ihiSj" rel="nofollow">http://fedecarg.codepad.org/Uq9ihiSj</a></p>
<p>Q #2:<br />
<a href="http://codepad.org/v8cj85Mk" rel="nofollow">http://codepad.org/v8cj85Mk</a> (clone the entity object)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Emran Hasan</title>
		<link>http://blog.fedecarg.com/2009/09/19/zend-framework-dal-daos-and-datamappers/#comment-4950</link>
		<dc:creator><![CDATA[Emran Hasan]]></dc:creator>
		<pubDate>Sun, 22 Nov 2009 18:28:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.fedecarg.com/?p=1713#comment-4950</guid>
		<description><![CDATA[Hi Federico,

Great post with nice examples. I&#039;m going to follow this in one of my projects soon and a few question struck me. Thought I&#039;d share here.

I am curious about a scenario where a record retrieval depends on sub records. For example, let&#039;s say we store multiple addresses for each user as follows:

&lt;code&gt;
CREATE TABLE `address` (
 `id` int(11) NOT NULL auto_increment,
 `user_id` int(11) NOT NULL,
 `street` varchar(100) NULL,
 `city` varchar(100) NULL,
 `state` varchar(100) NULL,
 PRIMARY KEY  (`id`)
)
&lt;/code&gt;

Now, when I use $user-&gt;getAddresses() function from controller, I expect to receive the addresses associated with this user entity. How should this be handled - in the Entity and Mapper ?

Another question of mine, when we are doing dependency injection as the following code:

&lt;code&gt;
$mapper = new Project_DataMapper_User();
        $mapper-&gt;setEntity(new Project_Entity_User());
        $user = $mapper-&gt;get($id);
&lt;/code&gt;

How should I return multiple instance of the entity, for example in a $mapper-&gt;getBySomeCriteria function?

I appreciate any help and thanks in advance.]]></description>
		<content:encoded><![CDATA[<p>Hi Federico,</p>
<p>Great post with nice examples. I&#8217;m going to follow this in one of my projects soon and a few question struck me. Thought I&#8217;d share here.</p>
<p>I am curious about a scenario where a record retrieval depends on sub records. For example, let&#8217;s say we store multiple addresses for each user as follows:</p>
<p><code><br />
CREATE TABLE `address` (<br />
 `id` int(11) NOT NULL auto_increment,<br />
 `user_id` int(11) NOT NULL,<br />
 `street` varchar(100) NULL,<br />
 `city` varchar(100) NULL,<br />
 `state` varchar(100) NULL,<br />
 PRIMARY KEY  (`id`)<br />
)<br />
</code></p>
<p>Now, when I use $user-&gt;getAddresses() function from controller, I expect to receive the addresses associated with this user entity. How should this be handled &#8211; in the Entity and Mapper ?</p>
<p>Another question of mine, when we are doing dependency injection as the following code:</p>
<p><code><br />
$mapper = new Project_DataMapper_User();<br />
        $mapper-&gt;setEntity(new Project_Entity_User());<br />
        $user = $mapper-&gt;get($id);<br />
</code></p>
<p>How should I return multiple instance of the entity, for example in a $mapper-&gt;getBySomeCriteria function?</p>
<p>I appreciate any help and thanks in advance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RRL</title>
		<link>http://blog.fedecarg.com/2009/09/19/zend-framework-dal-daos-and-datamappers/#comment-4554</link>
		<dc:creator><![CDATA[RRL]]></dc:creator>
		<pubDate>Wed, 23 Sep 2009 22:16:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.fedecarg.com/?p=1713#comment-4554</guid>
		<description><![CDATA[Hi guys what about making DAO/DAL generator not via yaml or xml but via db mapper, like Henrik Hussfelt does: http://hussfelt.net/labs/zend-model-creator ?

Only issues I spot there are composite primary key mapping problems (always gets the last one instead native primary key) and some Flex/AMF incompatibilities (returned arrays are empty and need recast).]]></description>
		<content:encoded><![CDATA[<p>Hi guys what about making DAO/DAL generator not via yaml or xml but via db mapper, like Henrik Hussfelt does: <a href="http://hussfelt.net/labs/zend-model-creator" rel="nofollow">http://hussfelt.net/labs/zend-model-creator</a> ?</p>
<p>Only issues I spot there are composite primary key mapping problems (always gets the last one instead native primary key) and some Flex/AMF incompatibilities (returned arrays are empty and need recast).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zend Framework University</title>
		<link>http://blog.fedecarg.com/2009/09/19/zend-framework-dal-daos-and-datamappers/#comment-4553</link>
		<dc:creator><![CDATA[Zend Framework University]]></dc:creator>
		<pubDate>Wed, 23 Sep 2009 17:33:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.fedecarg.com/?p=1713#comment-4553</guid>
		<description><![CDATA[[...] his latest post Federico Cargnelutti shows how DAO, DAL and Data Mappers can be implemented in Zend Framework. He [...]]]></description>
		<content:encoded><![CDATA[<p>[...] his latest post Federico Cargnelutti shows how DAO, DAL and Data Mappers can be implemented in Zend Framework. He [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

