<?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: Is it important that Views pull data from Models on their own?</title> <atom:link href="http://www.rvdavid.net/is-it-important-that-views-pull-data-from-models-on-their-own/feed/" rel="self" type="application/rss+xml" /><link>http://www.rvdavid.net/is-it-important-that-views-pull-data-from-models-on-their-own/</link> <description>A periodical blog of experiences from the angle of an autodidactic, paranoid and narcissistic web developer...</description> <lastBuildDate>Mon, 16 Aug 2010 12:08:43 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.1</generator><meta
xmlns="http://www.w3.org/1999/xhtml" name="robots" content="noindex,follow" /> <item><title>By: Bill Karwin</title><link>http://www.rvdavid.net/is-it-important-that-views-pull-data-from-models-on-their-own/#comment-1106</link> <dc:creator>Bill Karwin</dc:creator> <pubDate>Sun, 24 Jan 2010 22:55:20 +0000</pubDate> <guid
isPermaLink="false">http://www.rvdavid.net/?p=363#comment-1106</guid> <description>I agree that one should not feel limited by one way to do it.Designing the Model is equivalent to doing the OO design for all your application business logic.  I don&#039;t think there&#039;s a legitimate one-size-fits-all solution.In &quot;Facts and Fallacies of Software Engineering&quot; Robert L. Glass says,
&quot;Eighty percent of software work is intellectual. A fair amount of it is creative. Little of it is clerical.&quot;I assert that any framework helps with the part of coding that is clerical.  A framework is meant to simplify the repetitive work that really does have common implementation in all apps.This doesn&#039;t work for the Model, because it&#039;s too hard to make a generalization about what a Model does.  Trying to make a general-use framework for Models either sacrifices flexibility that you need, or else results in a framework that retains flexibility, but has usage that is complex that it gives no benefit compared to writing the app directly.</description> <content:encoded><![CDATA[<p>I agree that one should not feel limited by one way to do it.</p><p>Designing the Model is equivalent to doing the OO design for all your application business logic.  I don&#8217;t think there&#8217;s a legitimate one-size-fits-all solution.</p><p>In &#8220;Facts and Fallacies of Software Engineering&#8221; Robert L. Glass says,<br
/> &#8220;Eighty percent of software work is intellectual. A fair amount of it is creative. Little of it is clerical.&#8221;</p><p>I assert that any framework helps with the part of coding that is clerical.  A framework is meant to simplify the repetitive work that really does have common implementation in all apps.</p><p>This doesn&#8217;t work for the Model, because it&#8217;s too hard to make a generalization about what a Model does.  Trying to make a general-use framework for Models either sacrifices flexibility that you need, or else results in a framework that retains flexibility, but has usage that is complex that it gives no benefit compared to writing the app directly.</p> ]]></content:encoded> </item> <item><title>By: rvdavid</title><link>http://www.rvdavid.net/is-it-important-that-views-pull-data-from-models-on-their-own/#comment-1092</link> <dc:creator>rvdavid</dc:creator> <pubDate>Sun, 24 Jan 2010 11:08:00 +0000</pubDate> <guid
isPermaLink="false">http://www.rvdavid.net/?p=363#comment-1092</guid> <description>Thank you to everyone who has chimed in with their comments and opinions especially to Bill and Padraic. You guys have confirmed, for me anyway, that it is perfectly fine to pass the model object to the view from the controller.I am very happy with the feedback and have confirmed a bunch of theories I&#039;ve been throwing around in my mind for some time now.Thank you!</description> <content:encoded><![CDATA[<p>Thank you to everyone who has chimed in with their comments and opinions especially to Bill and Padraic. You guys have confirmed, for me anyway, that it is perfectly fine to pass the model object to the view from the controller.</p><p>I am very happy with the feedback and have confirmed a bunch of theories I&#8217;ve been throwing around in my mind for some time now.</p><p>Thank you!</p> ]]></content:encoded> </item> <item><title>By: rvdavid</title><link>http://www.rvdavid.net/is-it-important-that-views-pull-data-from-models-on-their-own/#comment-1091</link> <dc:creator>rvdavid</dc:creator> <pubDate>Sun, 24 Jan 2010 11:05:06 +0000</pubDate> <guid
isPermaLink="false">http://www.rvdavid.net/?p=363#comment-1091</guid> <description>Padraic!Thank you for chiming in on this subject matter.Thank you for your feedback which adds to Bill&#039;s recommendation of passing the model object to the view rather than passing the data returned by the model to the view.This feedback is basically what I was after. Getting responses from those who have more experience than I do on this and confirming certain directions I&#039;m trying to explore.I feel like you are again are there standing with a flag at the Checkpoint showing me which direction to go  as you have been at Zend Nabble forums several months ago giving guidance on why models should not extend Zend_Db_Table.&quot;why fight KISS?&quot; affirms a few ideas and directions I&#039;ve been thinking of heading at this point in time.Thanks again. I am eternally grateful!</description> <content:encoded><![CDATA[<p>Padraic!</p><p>Thank you for chiming in on this subject matter.</p><p>Thank you for your feedback which adds to Bill&#8217;s recommendation of passing the model object to the view rather than passing the data returned by the model to the view.</p><p>This feedback is basically what I was after. Getting responses from those who have more experience than I do on this and confirming certain directions I&#8217;m trying to explore.</p><p>I feel like you are again are there standing with a flag at the Checkpoint showing me which direction to go  as you have been at Zend Nabble forums several months ago giving guidance on why models should not extend Zend_Db_Table.</p><p>&#8220;why fight KISS?&#8221; affirms a few ideas and directions I&#8217;ve been thinking of heading at this point in time.</p><p>Thanks again. I am eternally grateful!</p> ]]></content:encoded> </item> <item><title>By: Pádraic Brady</title><link>http://www.rvdavid.net/is-it-important-that-views-pull-data-from-models-on-their-own/#comment-1081</link> <dc:creator>Pádraic Brady</dc:creator> <pubDate>Sat, 23 Jan 2010 21:17:51 +0000</pubDate> <guid
isPermaLink="false">http://www.rvdavid.net/?p=363#comment-1081</guid> <description>I think there&#039;s a few strands to the debate over View Helpers.The first one is to be careful of an absolutist approach. Most of us are guilty of presenting one way of accompishing a task to the exclusion of all else, not always because because we believe it&#039;s the One-True-Way, but because it suits the example we provide. This leads to the fallacy that a View Helper *must* as opposed to *may* look after its own models. In reality, if doing it from a controller is simpler (KISS) without sacrificing both testing capability (testability) and reusability, then there&#039;s not much wrong with it. This is most evident in in-out models - where a View needs a specific Model, but does not itself have much information on WHICH model. Then you have a choice of a) pass the ID, or b) pass the Model itself from a controller. Which is simpler? ;)The second is what constitutes a model. Like Bill, I&#039;d argue the model provided to a View should be the actual object itself. It costs little (compared to converting to yet another value, not a reference, like an array), offers greater flexibility and the advantage of Model provided methods to the View, and splits the Model View between the View hosted model and its View Helper hosted formatting helpers.The third, and the one where View Helpers and Models are most likely to be completely warranted, are when the Model is independent of the immediate purpose of the request. This is most obvious in layouts, where the main content is purpose of the request (so its models may come direct from the controller) but it is surrounded by other pieces of markup derived from other models not related to that request. Consider a a blog displaying entries which might also present a summary of comments. The comments are not the purpose of the request (that&#039;s the entries), so the comments are most likely to be derived from a View Helper directly querying a Model it knows about itself. More relevantly, these additional models tend to need nothing (or very little) from the controller.The key to View Helpers and Models is whether it passes a specific rule, and the rule is simple. Controllers are not Page Controllers. They handle the request at hand, but nothing else if possible. The everything else that&#039;s possible will sit in the View and/or Model leaving the controller thinner, lighter and specific. If its specific nature makes it easier to pass a specific Model to the View directly, well, why fight KISS? :P</description> <content:encoded><![CDATA[<p>I think there&#8217;s a few strands to the debate over View Helpers.</p><p>The first one is to be careful of an absolutist approach. Most of us are guilty of presenting one way of accompishing a task to the exclusion of all else, not always because because we believe it&#8217;s the One-True-Way, but because it suits the example we provide. This leads to the fallacy that a View Helper *must* as opposed to *may* look after its own models. In reality, if doing it from a controller is simpler (KISS) without sacrificing both testing capability (testability) and reusability, then there&#8217;s not much wrong with it. This is most evident in in-out models &#8211; where a View needs a specific Model, but does not itself have much information on WHICH model. Then you have a choice of a) pass the ID, or b) pass the Model itself from a controller. Which is simpler? <img
src='http://www.rvdavid.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p>The second is what constitutes a model. Like Bill, I&#8217;d argue the model provided to a View should be the actual object itself. It costs little (compared to converting to yet another value, not a reference, like an array), offers greater flexibility and the advantage of Model provided methods to the View, and splits the Model View between the View hosted model and its View Helper hosted formatting helpers.</p><p>The third, and the one where View Helpers and Models are most likely to be completely warranted, are when the Model is independent of the immediate purpose of the request. This is most obvious in layouts, where the main content is purpose of the request (so its models may come direct from the controller) but it is surrounded by other pieces of markup derived from other models not related to that request. Consider a a blog displaying entries which might also present a summary of comments. The comments are not the purpose of the request (that&#8217;s the entries), so the comments are most likely to be derived from a View Helper directly querying a Model it knows about itself. More relevantly, these additional models tend to need nothing (or very little) from the controller.</p><p>The key to View Helpers and Models is whether it passes a specific rule, and the rule is simple. Controllers are not Page Controllers. They handle the request at hand, but nothing else if possible. The everything else that&#8217;s possible will sit in the View and/or Model leaving the controller thinner, lighter and specific. If its specific nature makes it easier to pass a specific Model to the View directly, well, why fight KISS? <img
src='http://www.rvdavid.net/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /></p> ]]></content:encoded> </item> <item><title>By: Dalibor Karlovi?</title><link>http://www.rvdavid.net/is-it-important-that-views-pull-data-from-models-on-their-own/#comment-1047</link> <dc:creator>Dalibor Karlovi?</dc:creator> <pubDate>Fri, 22 Jan 2010 14:58:30 +0000</pubDate> <guid
isPermaLink="false">http://www.rvdavid.net/?p=363#comment-1047</guid> <description>Hi,I&#039;ve found that you need model access from your view if you have two-layer caching (model-level and view-level) which is needed if you use the same model for your WS&#039;s and web pages with very complex view logic. The rendering itself takes a time long enough to cache it, but you also need to cache the data on it&#039;s own.</description> <content:encoded><![CDATA[<p>Hi,</p><p>I&#8217;ve found that you need model access from your view if you have two-layer caching (model-level and view-level) which is needed if you use the same model for your WS&#8217;s and web pages with very complex view logic. The rendering itself takes a time long enough to cache it, but you also need to cache the data on it&#8217;s own.</p> ]]></content:encoded> </item> <item><title>By: Paul</title><link>http://www.rvdavid.net/is-it-important-that-views-pull-data-from-models-on-their-own/#comment-1044</link> <dc:creator>Paul</dc:creator> <pubDate>Fri, 22 Jan 2010 14:21:43 +0000</pubDate> <guid
isPermaLink="false">http://www.rvdavid.net/?p=363#comment-1044</guid> <description>Two ways this can go.. but are interesting.  One, instead of injecting the model you decorator the model with a class that knows about displaying itself.  This way in the view, like you say its much simpler.  Also easier then to reuse your model in terms of its view.  By decorating you keep adding decorators, to slightly change the display.   The other side of this is that by adding a model to your view you have to open up your open with a bunch of getters/setters which usually breaks Encapsulation.  The approach for this would be some of DTO object you can pass from the model layer to the view.  This way you do not have to expose your model, and you still have an object.</description> <content:encoded><![CDATA[<p>Two ways this can go.. but are interesting.  One, instead of injecting the model you decorator the model with a class that knows about displaying itself.  This way in the view, like you say its much simpler.  Also easier then to reuse your model in terms of its view.  By decorating you keep adding decorators, to slightly change the display.   The other side of this is that by adding a model to your view you have to open up your open with a bunch of getters/setters which usually breaks Encapsulation.  The approach for this would be some of DTO object you can pass from the model layer to the view.  This way you do not have to expose your model, and you still have an object.</p> ]]></content:encoded> </item> <item><title>By: Yv@n</title><link>http://www.rvdavid.net/is-it-important-that-views-pull-data-from-models-on-their-own/#comment-1042</link> <dc:creator>Yv@n</dc:creator> <pubDate>Fri, 22 Jan 2010 13:27:31 +0000</pubDate> <guid
isPermaLink="false">http://www.rvdavid.net/?p=363#comment-1042</guid> <description>Okay, seems like there was some stripping in the post so this part was lost in /dev/null :)In that particular script I start the code with:
...
$translate = Zend_Registry::get(&#039;Zend_Translate&#039;);
...
and then ofc it works.</description> <content:encoded><![CDATA[<p>Okay, seems like there was some stripping in the post so this part was lost in /dev/null <img
src='http://www.rvdavid.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>In that particular script I start the code with:<br
/> &#8230;<br
/> $translate = Zend_Registry::get(&#8216;Zend_Translate&#8217;);<br
/> &#8230;<br
/> and then ofc it works.</p> ]]></content:encoded> </item> <item><title>By: Yv@n</title><link>http://www.rvdavid.net/is-it-important-that-views-pull-data-from-models-on-their-own/#comment-1041</link> <dc:creator>Yv@n</dc:creator> <pubDate>Fri, 22 Jan 2010 13:23:52 +0000</pubDate> <guid
isPermaLink="false">http://www.rvdavid.net/?p=363#comment-1041</guid> <description>I&#039;m a bit new to the whole MVC concept myself. Never really used anything like it before, as I only had a view/code setup with smarty before I started experimenting with ZF in 2009 Jan.
Because of that my only source of how things &#039;should&#039; look like, is from php/zf point of view (at least thats how I interpretted what I&#039;ve read up till now :) )To me the view scrits are meant to be as simple as possible; I&#039;m always trying to keep it as clean of unnecessary code as possible. (I actually struggle when I feel I&#039;m calling something from a view script when there should be a cleaner method of achieving the same goal.)If I do it like that I can work on the important stuff in the controller, while leaving the more trivial stuff, lik layout and styling to my biorobot co-workers who ar enot as deep in ZF yet as I am.For this approach passing the variables that are needed from the controller to the view seems somewhat better to me, than exposing the whole object in the view script.This is something I&#039;ve came across just today, and I feel like its related to your problem, so I&#039;m curious about your opinion:I&#039;m building a site with I18 support, the layout, views, forms, etc. are all localized.
As I&#039;m using the Translator Bootstrap resource(at this point its undocumented on the ZF site, but its been available for a while, like some other resources /layout for example/), I&#039;ve set up the translator with some nice and clean code.application.ini:
...
resources.translate.data = APPLICATION_PATH &quot;/translations&quot;
resources.translate.adapter = &quot;Array&quot;
resources.translate.options.scan = &quot;filename&quot;
...and in the Bootstrap.php:
...
protected function _initTranslator() {
$this-&gt;bootstrap(array(&#039;layout&#039;,&#039;view&#039;));
$translate = $this-&gt;bootstrap(&#039;translate&#039;)-&gt;getResource(&#039;translate&#039;);
$layout = $this-&gt;getResource(&#039;layout&#039;);
$view   = $this-&gt;getResource(&#039;view&#039;);
$layout-&gt;translate = $translate;
$view-&gt;translate   = $translate;
return $translate;
}
...So this way I can access the translator in the layout script and the view scripts as $this-&gt;translate and localization works out of the box.Also the Translator bootstrap resource registers the translator in the Zend_Registry as the Zend_Translate key, so whatever i18 aware component you use in your code it also works.The only thing that didn&#039;t work like that was a special form, where I use the viewscript form decorator, and it doesn&#039;t inherit things from the view, so the translator is unavailable in that code segment. Its also one of the &quot;not that well documented&quot; parts of ZF. (The element view script decorator has some documentation, but the form version lacks it...I&#039;ve spent a few hours with trial by error method, also browsing through the ZF library code, about what is available for use with it.)In that particulare script I start the code with:
and then ofc it works.My problem is that somehow this feels bad...I don&#039;t know why, but I feel uneasy asif I&#039;m doing it wrong. Fetching something from the global registry in a view script.What do you think?</description> <content:encoded><![CDATA[<p>I&#8217;m a bit new to the whole MVC concept myself. Never really used anything like it before, as I only had a view/code setup with smarty before I started experimenting with ZF in 2009 Jan.<br
/> Because of that my only source of how things &#8216;should&#8217; look like, is from php/zf point of view (at least thats how I interpretted what I&#8217;ve read up till now <img
src='http://www.rvdavid.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> )</p><p>To me the view scrits are meant to be as simple as possible; I&#8217;m always trying to keep it as clean of unnecessary code as possible. (I actually struggle when I feel I&#8217;m calling something from a view script when there should be a cleaner method of achieving the same goal.)</p><p>If I do it like that I can work on the important stuff in the controller, while leaving the more trivial stuff, lik layout and styling to my biorobot co-workers who ar enot as deep in ZF yet as I am.</p><p>For this approach passing the variables that are needed from the controller to the view seems somewhat better to me, than exposing the whole object in the view script.</p><p>This is something I&#8217;ve came across just today, and I feel like its related to your problem, so I&#8217;m curious about your opinion:</p><p>I&#8217;m building a site with I18 support, the layout, views, forms, etc. are all localized.<br
/> As I&#8217;m using the Translator Bootstrap resource(at this point its undocumented on the ZF site, but its been available for a while, like some other resources /layout for example/), I&#8217;ve set up the translator with some nice and clean code.</p><p>application.ini:<br
/> &#8230;<br
/> resources.translate.data = APPLICATION_PATH &#8220;/translations&#8221;<br
/> resources.translate.adapter = &#8220;Array&#8221;<br
/> resources.translate.options.scan = &#8220;filename&#8221;<br
/> &#8230;</p><p>and in the Bootstrap.php:<br
/> &#8230;<br
/> protected function _initTranslator() {<br
/> $this-&gt;bootstrap(array(&#8216;layout&#8217;,'view&#8217;));<br
/> $translate = $this-&gt;bootstrap(&#8216;translate&#8217;)-&gt;getResource(&#8216;translate&#8217;);<br
/> $layout = $this-&gt;getResource(&#8216;layout&#8217;);<br
/> $view   = $this-&gt;getResource(&#8216;view&#8217;);<br
/> $layout-&gt;translate = $translate;<br
/> $view-&gt;translate   = $translate;<br
/> return $translate;<br
/> }<br
/> &#8230;</p><p>So this way I can access the translator in the layout script and the view scripts as $this-&gt;translate and localization works out of the box.</p><p>Also the Translator bootstrap resource registers the translator in the Zend_Registry as the Zend_Translate key, so whatever i18 aware component you use in your code it also works.</p><p>The only thing that didn&#8217;t work like that was a special form, where I use the viewscript form decorator, and it doesn&#8217;t inherit things from the view, so the translator is unavailable in that code segment. Its also one of the &#8220;not that well documented&#8221; parts of ZF. (The element view script decorator has some documentation, but the form version lacks it&#8230;I&#8217;ve spent a few hours with trial by error method, also browsing through the ZF library code, about what is available for use with it.)</p><p>In that particulare script I start the code with:</p><p>and then ofc it works.</p><p>My problem is that somehow this feels bad&#8230;I don&#8217;t know why, but I feel uneasy asif I&#8217;m doing it wrong. Fetching something from the global registry in a view script.</p><p>What do you think?</p> ]]></content:encoded> </item> <item><title>By: Bill Karwin</title><link>http://www.rvdavid.net/is-it-important-that-views-pull-data-from-models-on-their-own/#comment-1025</link> <dc:creator>Bill Karwin</dc:creator> <pubDate>Fri, 22 Jan 2010 07:58:37 +0000</pubDate> <guid
isPermaLink="false">http://www.rvdavid.net/?p=363#comment-1025</guid> <description>David, wouldn&#039;t that be the Visitor pattern?  I&#039;m not well-read enough on all my patterns.  :-)</description> <content:encoded><![CDATA[<p>David, wouldn&#8217;t that be the Visitor pattern?  I&#8217;m not well-read enough on all my patterns. <img
src='http://www.rvdavid.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p> ]]></content:encoded> </item> <item><title>By: David Penner</title><link>http://www.rvdavid.net/is-it-important-that-views-pull-data-from-models-on-their-own/#comment-1016</link> <dc:creator>David Penner</dc:creator> <pubDate>Fri, 22 Jan 2010 03:57:48 +0000</pubDate> <guid
isPermaLink="false">http://www.rvdavid.net/?p=363#comment-1016</guid> <description>This might be going over the edge a bit but perhaps Bill&#039;s idea could be construed as a &quot;Strategy&quot; pattern in terms of how something is represented as a string depending on the context. For example, if I&#039;m in a view script I&#039;d want __toString() to return a valid (x)html fragment, if i&#039;m doing xml-rpc i&#039;d want xml, if i&#039;m doing json-rpc or ajax i&#039;d want json, etc. In some way this might be an extension of the relationship between __sleep() and serialize()/unserialize().Maybe this is just a purely academic idea though ... not sure if this would offer any *real* productivity gains at the cost of some complexity. The main issue would seem to be where and how to select the context. Probably in a boostrap script or something.Plus this might complicate issues where one has to work with a designer in the case of html.</description> <content:encoded><![CDATA[<p>This might be going over the edge a bit but perhaps Bill&#8217;s idea could be construed as a &#8220;Strategy&#8221; pattern in terms of how something is represented as a string depending on the context. For example, if I&#8217;m in a view script I&#8217;d want __toString() to return a valid (x)html fragment, if i&#8217;m doing xml-rpc i&#8217;d want xml, if i&#8217;m doing json-rpc or ajax i&#8217;d want json, etc. In some way this might be an extension of the relationship between __sleep() and serialize()/unserialize().</p><p>Maybe this is just a purely academic idea though &#8230; not sure if this would offer any *real* productivity gains at the cost of some complexity. The main issue would seem to be where and how to select the context. Probably in a boostrap script or something.</p><p>Plus this might complicate issues where one has to work with a designer in the case of html.</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)
Database Caching using disk

Served from: www.rvdavid.net @ 2010-09-10 20:24:51 -->