<?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/"
		>
<channel>
	<title>Comments on: Should you use Model::query() in the controller?</title>
	<atom:link href="http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/</link>
	<description>baking cakes with CakePHP</description>
	<lastBuildDate>Sat, 13 Mar 2010 06:19:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/comment-page-1/#comment-142049</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Sat, 12 Dec 2009 17:42:03 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/#comment-142049</guid>
		<description>@Stefan: Thanks for your comment!

I agree with you and I think it would even make sense to enforce this by making the query() method protected, so that it can only be used from within a model.</description>
		<content:encoded><![CDATA[<p>@Stefan: Thanks for your comment!</p>
<p>I agree with you and I think it would even make sense to enforce this by making the query() method protected, so that it can only be used from within a model.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stefan</title>
		<link>http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/comment-page-1/#comment-142009</link>
		<dc:creator>Stefan</dc:creator>
		<pubDate>Fri, 11 Dec 2009 20:51:44 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/#comment-142009</guid>
		<description>As I&#039;ve worked a lot with the Mapper Pattern. I like the second idea better as well. You should use the Model to execute the queries. 

So therefore. For every query you would execute you would create a method in the model.

This keeps the controller more readable and the Model does it&#039;s job like it should. It&#039;s actually a mapper to the database so use it as one.</description>
		<content:encoded><![CDATA[<p>As I&#8217;ve worked a lot with the Mapper Pattern. I like the second idea better as well. You should use the Model to execute the queries. </p>
<p>So therefore. For every query you would execute you would create a method in the model.</p>
<p>This keeps the controller more readable and the Model does it&#8217;s job like it should. It&#8217;s actually a mapper to the database so use it as one.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/comment-page-1/#comment-6234</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Tue, 17 Apr 2007 17:02:20 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/#comment-6234</guid>
		<description>@Tim: Thanks for your comment. To avoid the problem you described you could use the approach explained in http://bakery.cakephp.org/articles/view/185</description>
		<content:encoded><![CDATA[<p>@Tim: Thanks for your comment. To avoid the problem you described you could use the approach explained in <a href="http://bakery.cakephp.org/articles/view/185" rel="nofollow">http://bakery.cakephp.org/articles/view/185</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim</title>
		<link>http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/comment-page-1/#comment-6232</link>
		<dc:creator>Tim</dc:creator>
		<pubDate>Tue, 17 Apr 2007 10:05:32 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/#comment-6232</guid>
		<description>When I got started with CakePHP I was also wondering where to put custom queries. You should indeed put them inside the model at all times. Even though it may seem you will only use the query once at the time, it`s still possible you will need it elsewhere as you make progress in developing your application.

More or less related: For a similar reason I don`t like the way the recursive option works in Cake: When you add tables in your database as you are developing, existing code might pull in data from tables you don`t care about.</description>
		<content:encoded><![CDATA[<p>When I got started with CakePHP I was also wondering where to put custom queries. You should indeed put them inside the model at all times. Even though it may seem you will only use the query once at the time, it`s still possible you will need it elsewhere as you make progress in developing your application.</p>
<p>More or less related: For a similar reason I don`t like the way the recursive option works in Cake: When you add tables in your database as you are developing, existing code might pull in data from tables you don`t care about.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/comment-page-1/#comment-5811</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Tue, 20 Mar 2007 17:53:05 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/#comment-5811</guid>
		<description>@Jonathan: Yes, in the RoR article they call the model attributes directly to get the data. That&#039;s not possible with Cake, as Cake works in the current versions with arrays and not with objects. 

I think it depends on the point of view whether you call cake a MVC framework or a PAC framework. But in the end it&#039;s not that important...</description>
		<content:encoded><![CDATA[<p>@Jonathan: Yes, in the RoR article they call the model attributes directly to get the data. That&#8217;s not possible with Cake, as Cake works in the current versions with arrays and not with objects. </p>
<p>I think it depends on the point of view whether you call cake a MVC framework or a PAC framework. But in the end it&#8217;s not that important&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Freeman</title>
		<link>http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/comment-page-1/#comment-5775</link>
		<dc:creator>Jonathan Freeman</dc:creator>
		<pubDate>Mon, 19 Mar 2007 19:09:54 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/#comment-5775</guid>
		<description>@Cakebaker: That&#039;s too bad, then I would call Cake a PAC framework and not a MVC framework.

Later in the RoR article, the author illustrates that you call the model&#039;s methods directly from the view. When its read only data, there&#039;s no need to pull data into the controller and push it into the view.</description>
		<content:encoded><![CDATA[<p>@Cakebaker: That&#8217;s too bad, then I would call Cake a PAC framework and not a MVC framework.</p>
<p>Later in the RoR article, the author illustrates that you call the model&#8217;s methods directly from the view. When its read only data, there&#8217;s no need to pull data into the controller and push it into the view.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Freeman</title>
		<link>http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/comment-page-1/#comment-5774</link>
		<dc:creator>Jonathan Freeman</dc:creator>
		<pubDate>Mon, 19 Mar 2007 19:03:55 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/#comment-5774</guid>
		<description>@Cakebaker: Later in the article the author demos that you simple pull read only data straight from the model and no need to pull data from the controller and push it to the view. That&#039;s MVC and not MVC-like. That&#039;s why I question if Cake&#039;s view are aware of the models, which at first glance it is more like a PAC framework (MVC-like).

In the author&#039;s RoR example:
&lt;!-- app/views/people/index.rhtml --&gt;

  &quot;&gt;
    
    
  
</description>
		<content:encoded><![CDATA[<p>@Cakebaker: Later in the article the author demos that you simple pull read only data straight from the model and no need to pull data from the controller and push it to the view. That&#8217;s MVC and not MVC-like. That&#8217;s why I question if Cake&#8217;s view are aware of the models, which at first glance it is more like a PAC framework (MVC-like).</p>
<p>In the author&#8217;s RoR example:<br />
<!-- app/views/people/index.rhtml --></p>
<p>  &#8220;&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/comment-page-1/#comment-5771</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Mon, 19 Mar 2007 18:19:39 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/#comment-5771</guid>
		<description>@Jonathan: No, you cannot access a model from the view. The controller decides, which data go to the view. 

The same approach is also used in the RoR article, the find method is called in the controller, which then makes the data available for the view.</description>
		<content:encoded><![CDATA[<p>@Jonathan: No, you cannot access a model from the view. The controller decides, which data go to the view. </p>
<p>The same approach is also used in the RoR article, the find method is called in the controller, which then makes the data available for the view.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Freeman</title>
		<link>http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/comment-page-1/#comment-5767</link>
		<dc:creator>Jonathan Freeman</dc:creator>
		<pubDate>Mon, 19 Mar 2007 15:49:02 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/#comment-5767</guid>
		<description>Is there any way to &#039;pull&#039; data from the models directly from the views? How would you go about calling model methods directly from the view instead of the controller pushing data to the view? Is it as simple as $this-&gt;Model-&gt;myMethod() within the views? I&#039;ve yet to see any example of this in Cake.

In the article that Joel posted, RoR can simple make calls to its model completely by passing the controller for reading data.

If you the views are not aware of the models, then I&#039;m questioning if Cake is a true MVC framework, but perhaps more of the PAC framework.</description>
		<content:encoded><![CDATA[<p>Is there any way to &#8216;pull&#8217; data from the models directly from the views? How would you go about calling model methods directly from the view instead of the controller pushing data to the view? Is it as simple as $this-&gt;Model-&gt;myMethod() within the views? I&#8217;ve yet to see any example of this in Cake.</p>
<p>In the article that Joel posted, RoR can simple make calls to its model completely by passing the controller for reading data.</p>
<p>If you the views are not aware of the models, then I&#8217;m questioning if Cake is a true MVC framework, but perhaps more of the PAC framework.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CraZyLeGs</title>
		<link>http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/comment-page-1/#comment-5087</link>
		<dc:creator>CraZyLeGs</dc:creator>
		<pubDate>Sat, 03 Mar 2007 02:20:35 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/#comment-5087</guid>
		<description>from a semantic POV, $this-&gt;Model-&gt;getProductsBySomeCriteria()
is far more meaningful than $this-&gt;model-&gt;query($bloatedYAY);

specially when your prototyping, workflow etc..

in a collaborative environment it becomes more crucial, someone will read your code, of course you can put comments in there (and you should)..but separating that piece of code and putting it where it should be the best, is helpful. because that person who&#039;s reading your code can understand what you&#039;re doing and continue reading the flow of your code, later he will decide to discover further by reading that function. and he already knows what it&#039;s doing, he now wants to know how it was done.</description>
		<content:encoded><![CDATA[<p>from a semantic POV, $this-&gt;Model-&gt;getProductsBySomeCriteria()<br />
is far more meaningful than $this-&gt;model-&gt;query($bloatedYAY);</p>
<p>specially when your prototyping, workflow etc..</p>
<p>in a collaborative environment it becomes more crucial, someone will read your code, of course you can put comments in there (and you should)..but separating that piece of code and putting it where it should be the best, is helpful. because that person who&#8217;s reading your code can understand what you&#8217;re doing and continue reading the flow of your code, later he will decide to discover further by reading that function. and he already knows what it&#8217;s doing, he now wants to know how it was done.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
