<?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>rvdavid: A Web Developer&#039;s Blog &#187; Zend Framework</title> <atom:link href="http://www.rvdavid.net/tag/zend-framework/feed/" rel="self" type="application/rss+xml" /><link>http://www.rvdavid.net</link> <description>A periodical blog of experiences from the angle of an autodidactic, paranoid and narcissistic web developer...</description> <lastBuildDate>Wed, 01 Sep 2010 12:47:15 +0000</lastBuildDate> <language>en</language> <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>Is it important that Views pull data from Models on their own?</title><link>http://www.rvdavid.net/is-it-important-that-views-pull-data-from-models-on-their-own/</link> <comments>http://www.rvdavid.net/is-it-important-that-views-pull-data-from-models-on-their-own/#comments</comments> <pubDate>Thu, 21 Jan 2010 23:25:41 +0000</pubDate> <dc:creator>rvdavid</dc:creator> <category><![CDATA[Zend Framework]]></category> <category><![CDATA[mvc]]></category> <category><![CDATA[php]]></category> <category><![CDATA[Web Development]]></category><guid
isPermaLink="false">http://www.rvdavid.net/?p=363</guid> <description><![CDATA[In my recent post regarding the Model Service layer, there was one query about me mentioning that the View is configured by the Controller which goes against the grain of traditional MVC idea of &#8220;Views Should handle their own Models / data&#8221;. There is nothing wrong with Views being able to handle their own models, [...]]]></description> <content:encoded><![CDATA[<div
class="adsense adsense-leadin" style="float:right;margin: 12px;"><script type="text/javascript">google_ad_client = "pub-3968550303568935";
/* 250x250, created 07/06/10 */
google_ad_slot = "3782770990";
google_ad_width = 250;
google_ad_height = 250;</script> <script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></div><p>In my recent post regarding the Model Service layer, there was one query about me mentioning that the View is configured by the Controller which goes against the grain of traditional MVC idea of &#8220;Views Should handle their own Models / data&#8221;.</p><p>There is nothing wrong with Views being able to handle their own models, I&#8217;m not suggesting that this shouldn&#8217;t be the case. You can also do it this way. That is the &#8220;traditional MVC&#8221; way of doing things and it works fine which is why I&#8217;m questioning why I&#8217;ve moved away from it. I&#8217;m just typing as I go so hopefully by the end of it, we&#8217;ll have something that makes a point.</p><h3>I used to Really love this sh*t!</h3><p>I used to trumpet the sh*t out of this because I had it figured out and it made me feel smart <img
src='http://www.rvdavid.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> . I thought hey, I can adhere to the traditional MVC way of things and make the View select it&#8217;s own Model (or models) and gather information on it&#8217;s own &#8211; all I need is a View Helper. Further along came the question &#8220;What about the times when the Model needs to be used by the Controller?&#8221; well I got a plan for this too, then there&#8217;s the &#8220;What about when the Controller and View need access to the same model?&#8221; case. I needed to create a strategy to make sure that the Model isn&#8217;t instantiated twice in these cases.</p><p><span
id="more-363"></span></p><h3>This is how I did it: Components you need to code up to make it so that the View can choose it&#8217;s own Models</h3><p><strong>Step 1:</strong> I created a Model Service Factory which I stored in Zend_Registry &#8211; the Model Service Factory has a Registry of it&#8217;s own and checks to see if an instance of the Model being requested already exists &#8211; if it does, it returns that instead of creating a new instance.<br
/> <strong> Step 2:</strong> I created a View Helper called &#8220;GetModel&#8221; which accesses the Zend_Registry to access the Model Service Factory and returns the model<br
/> <strong> Step 3:</strong> I then created an Action Helper called &#8220;GetModel&#8221; which worked exactly like the View Helper.</p><p>But then, I found myself questioning if the view selecting it&#8217;s own models / data applies to PHP<span
style="color: #ff0000;">, or if all this complexity is worth anything useful aside from saying &#8220;I can do it&#8221;</span>. Here are some of the things I&#8217;m thinking about:</p><ul><li>One of the cases that I&#8217;ve found cumbersome is when I need to access  request parameters in the View whether it be for creating a URL. This should be regarded as a data source as well. Does this mean that we have to code up View Helper to access this also? (This isn&#8217;t a smart ass rhetorical question either &#8211; I really want to know what do you do?)To handle cases where I need to display parameters in the view, I assign the view parameters in the controller something along the lines of:</li></ul><blockquote><p>$this-&gt;view-&gt;username = $this-&gt;_getParam(&#8216;username&#8217;);</p></blockquote><ul><li>Say you need to display session data in the view, how would you go about doing that? Personally, as with the request parameters, I assign the session data to the view in the controller:</li></ul><blockquote><p>$this-&gt;view-&gt;somesessiondata = $session-&gt;somedata;</p></blockquote><ul><li>Now say we need to get some data from the model&#8230; no problem!  I can use the getModel view helper that makes me feel so smart. To do this though, we need to set up the view so that it has the ID parameter.</li></ul><blockquote><p>$data = $this-&gt;getModel(&#8216;SomeModel&#8217;)-&gt;findById($this-&gt;id);<br
/> // or if we us a view helper for parameters (I said IF &#8211; not entirely sure about this yet)<br
/> $data = $this-&gt;getModel(&#8216;SomeModel&#8217;)-&gt;findById($this-&gt;getParam(&#8216;id&#8217;));</p></blockquote><p>Now compare this with providing the data that the view needs via the Controller.</p><blockquote><p>// in the controller<br
/> $this-&gt;view-&gt;data = $this-&gt;_service-&gt;findById($this-&gt;_getParam(&#8216;id&#8217;));<br
/> $this-&gt;view-&gt;username = $this-&gt;_getParam(&#8216;username&#8217;);<br
/> $session = new Zend_Session_NameSpace<br
/> $this-&gt;view-&gt;sessionData = $session-&gt;sessionData;</p><p>// in the view<br
/> &lt;h2&gt;User Details&lt;/h2&gt;<br
/> &lt;?php foreach ($data as $key=&gt;$val) : ?&gt;<br
/> &lt;?=$key?&gt;: &lt;?=$val;?&gt;<br
/> &lt;?php endforeach; ?&gt;</p><p>&lt;p&gt;You have requested the username: &lt;?=$this-&gt;username; ?&gt; which is not available. &lt;/p&gt;</p></blockquote><p>Also at one point I was thinking why we are fighting so hard to decouple the view from the controller anyway? They are coupled from the file system and have default conventions like indexAction is coupled with index.phtml view script in an index script directory (which matches controller name).</p><p>Having said that though, I don&#8217;t see a strong case <strong>for</strong> or <strong>against</strong> pushing or pulling models to or from the View. Maybe I&#8217;m just missing the point somewhere. In any case, I&#8217;d be grateful to know (and learn from) what your take is on this subject matter.</p><p>So to sum it up, these are the questions that are floating through my head at the moment.</p><ul><li>What are the _specific_ advantages of having the View pull data from the model directly?</li><li>What are the _specific_ disadvantages of having the Controller push data from the model into view member variables?</li><li>Is the example I specified above (creating view helpers, registry, action helpers) overkill just to achieve something that may or may not be a design problem?</li></ul> ]]></content:encoded> <wfw:commentRss>http://www.rvdavid.net/is-it-important-that-views-pull-data-from-models-on-their-own/feed/</wfw:commentRss> <slash:comments>19</slash:comments> </item> <item><title>My Zend Framework Model Layer: Part Service, Part ORM</title><link>http://www.rvdavid.net/my-zend-framework-model-layer-part-service-part-orm/</link> <comments>http://www.rvdavid.net/my-zend-framework-model-layer-part-service-part-orm/#comments</comments> <pubDate>Tue, 19 Jan 2010 17:38:29 +0000</pubDate> <dc:creator>rvdavid</dc:creator> <category><![CDATA[Zend Framework]]></category> <category><![CDATA[mvc]]></category> <category><![CDATA[php]]></category> <category><![CDATA[service layer]]></category> <category><![CDATA[Web Development]]></category><guid
isPermaLink="false">http://www.rvdavid.net/?p=307</guid> <description><![CDATA[The Model Layer of the MVC triad: I&#8217;ve been thinking this over for the past few months since using the Doctrine ORM and I think I&#8217;ve finally made some progress to get this issue licked. In the past, I&#8217;ve agonised over this issue and blogged about my progress. Some weeks or days later I tried to probe the [...]]]></description> <content:encoded><![CDATA[<p>The Model Layer of the MVC triad: I&#8217;ve been thinking this over for the past few months since using the Doctrine ORM and I think I&#8217;ve finally made some progress to get this issue licked. In the past, I&#8217;ve agonised over this issue and <a
title="Research into Possible Domain Model Solutions " href="http://www.rvdavid.net/zend-framework-model/" target="_blank">blogged about my progress</a>. Some weeks or days later I tried to probe the <a
title="How would you handle this? – Service Layer slowly getting polluted (or so it seems)! - Damn was I confused!" href="http://www.rvdavid.net/how-would-you-handle-this-service-layer-slowly-getting-polluted-or-so-it-seems/" target="_blank">community on what they would do</a>, Now I think I&#8217;d have an idea on what I would do.</p><p>After some more thought and lots of research on the subject, I&#8217;ve come to a solid point where I actually have something to try out which seems semantic aside from the naming of the class (Service Class) &#8211; but this is derived from what some people are talking about in ZF circles starting from Matthew Weier O&#8217;Phinney who was coining it as the &#8220;<a
title="check out the part with the sub heading: gateway to the domain" href="http://weierophinney.net/matthew/archives/202-Model-Infrastructure.html" target="_blank">Gateway to the Domain</a>&#8221; from early on, then later changing it to &#8220;Service Class&#8221;.</p><p><span
id="more-307"></span></p><h3>The Service Class</h3><p>So this is what I chose to go with:  For each model class, I&#8217;ve got a Database Agnostic Service class - in fact, it uses the Entities Produced by Doctrine ORM to talk to the database, but isn&#8217;t entirely reliant upon Doctrine to Provide the Model Layer on it&#8217;s own. Using Doctrine as your Model Layer alone I suppose is better than extending Zend_Db which is highly <a
title="Me getting schooled on Why Extending from Zend_Db is bad at Nabble" href="http://n4.nabble.com/Another-Model-Design-Thread-td670076.html" target="_blank">discouraged by everyone</a>, but you still have the database dependency.</p><p>I thought well, I&#8217;ve done a lot of feeling around the subject, maybe I&#8217;ll just ask around. So over to twitter I go. I sent <a
title="Dude, I always gotta go to your site to get your name! I can never spell it correctly!" href="http://weierophinney.net/matthew/" target="_blank">Matthew Weier O&#8217;Phinney</a> a tweet asking if it is right that Doctrine models are relatively empty whilst Model services are filled with business logic and <a
href="http://twitter.com/weierophinney/status/7464401031" target="_blank">he answered</a>: &#8220;Absolutely. Plain old PHP is perfect for entities.&#8221; but I had no idea WTF that meant.</p><p>The Service Layer uses the Model which is the Entity. <a
href="http://twitter.com/rvdavid/status/7465840295">My further attempt</a> to clarify the situation and continue discussion didn&#8217;t get a response &#8211; maybe because I had to condense words and use accronymns to fit the message in or he had just become too busy. So on my own I go again.</p><p>After mulling over it a few, I thought I&#8217;d just run with what I&#8217;ve got. It seems to be semantic, but it has a lot of responsibilities:</p><ul><li>The Model Service Class is a Resource.</li><li>The Model Service uses the ACL layer to check if a Role Identified has the Privileges to make it&#8217;s request prior to usage.</li><li>The Model Service creates Entities by using its Model Factory/Finder methods such as FindById it then returns either an array or an Entity based on what Hydration mode was specified (default is array).</li><li>The Model Service creates Forms and uses it for Validation</li><li>The Model Service provides the CRUD methods so that the Controller does not have to worry about instantiating and configuring models to Create Update or Delete data.</li><li>The Model Service uses Zend_Cache and can use caching on non-changing data such as lookup lists status or types and large collections of data used in drop downs, lists or datagrids.</li><li>Although there is no factory for it, the Model Service can create and use other Model Service classes.</li><li><del
datetime="2010-05-05T03:45:29+00:00">The Service Layer is not passed to the View either. The View is configured by the Controller and has data shoved into properties/member variables.</del></li><li>The Service Object can be passed to the View if required, so that the View can use the Sevice object to interrogate models on it&#8217;s own. We trust that those writing the View Markup will only be using the service object _strictly for reading only_.</li></ul><p>I&#8217;ve been working with this setup for a few weeks now. This method is very testable and makes for an extremely thin Controller Layer.</p><p>What do you guys think?</p><p>Have we over engineered this thing? Should it be called the Service Layer as more and more people are coining it as? What suggestions can you make to make this better?</p> ]]></content:encoded> <wfw:commentRss>http://www.rvdavid.net/my-zend-framework-model-layer-part-service-part-orm/feed/</wfw:commentRss> <slash:comments>37</slash:comments> </item> <item><title>Zend_Navigation makes writing Navigation for ZF Sites Very Easy</title><link>http://www.rvdavid.net/zend_navigation-makes-writing-navigation-for-zf-sites-very-easy/</link> <comments>http://www.rvdavid.net/zend_navigation-makes-writing-navigation-for-zf-sites-very-easy/#comments</comments> <pubDate>Thu, 14 Jan 2010 13:31:20 +0000</pubDate> <dc:creator>rvdavid</dc:creator> <category><![CDATA[Zend Framework]]></category> <category><![CDATA[Fast 15]]></category> <category><![CDATA[php]]></category><guid
isPermaLink="false">http://www.rvdavid.net/?p=291</guid> <description><![CDATA[Today, has been a very productive day for me. Part of it was spent on picking up Zend_Navigation which, thanks to Jon Lebensold&#8217;s Zend Cast on the subject of using Zend_Navigation to create menus, sitemaps and breadcrumbs, was easier than I had expected. Zend_Navigation makes the management of a web site&#8217;s navigation very easy as it [...]]]></description> <content:encoded><![CDATA[<p>Today, has been a very productive day for me. Part of it was spent on picking up Zend_Navigation which, thanks to Jon Lebensold&#8217;s Zend Cast on the subject of using <a
title="Check it out!" href="http://www.zendcasts.com/zend_navigation-dynamically-creating-a-menu-a-sitemap-and-breadcrumbs/2009/06/" target="_blank">Zend_Navigation to create menus, sitemaps and breadcrumbs</a>, was easier than I had expected.</p><p><a
title="Zend Navigation Documentation" href="http://framework.zend.com/manual/en/zend.navigation.html" target="_blank">Zend_Navigation</a> makes the management of a web site&#8217;s navigation very easy as it allows you to programmatically create the navigation bar by specifying either the URI or Controller, Action and Module properties of a Zend Navigation Page.</p><p>To use Zend Navigation, all I had to do was the following:</p><ul><li>Add configuration entries for navigation in the application.ini file.</li><li>Initialise and attach an instance of the Zend_Navigation container class to the navigation helper via the view in the bootstrap.</li><li>Display the navigation bar with Zend_View_Helper_Navigation::menu() or the BreadCrumbs with Zend_View_Helper_Navigation::breadcrumbs() in your layout.phtml file.</li></ul><p><span
id="more-291"></span></p><h3>Add configuration entries for navigation in the application.ini file</h3><p>Now I could have configured the Zend_Navigation container by passing the configuration options in an array, but I thought specifying the navigation in the application.ini was easier because it would keep my init method leaner (more on this later). So the first thing I had to do was add configuration entries for navigation in the application.ini file.</p><p>Here&#8217;s a code sample:</p><blockquote><p>; &#8212;<br
/> ; Navigation<br
/> ; &#8212;<br
/> navigation.home.label = home<br
/> navigation.home.controller = index<br
/> navigation.home.action = index<br
/> navigation.users.label = users<br
/> navigation.users.controller = system-user<br
/> navigation.users.action = index<br
/> navigation.help.label = help<br
/> navigation.help.controller = help<br
/> navigation.help.action = index</p></blockquote><h3>Initialise and attach an instance of the Zend_Navigation container class to the navigation helper via the view in the bootstrap</h3><p>Initialise the navigation object in the bootstrap class &#8211; well there&#8217;s no explanations needed here. See the code sample.</p><p>Here&#8217;s a code sample:</p><blockquote><p>protected function _initNavigation()<br
/> {<br
/> $this-&gt;bootstrap(&#8216;layout&#8217;);<br
/> $layout = $this-&gt;getResource(&#8216;layout&#8217;);<br
/> $view = $layout-&gt;getView();<br
/> $navigation = new Zend_Navigation($this-&gt;getOption(&#8216;navigation&#8217;));<br
/> $view-&gt;navigation($navigation);<br
/> }</p></blockquote><h3>Display the navigation bar with Zend_View_Helper_Navigation::menu() or the BreadCrumbs with Zend_View_Helper_Navigation::breadcrumbs() in your layout.phtml file</h3><p>The Navigation view helper has methods such as menu(), breadcrumbs() and some methods for generating a valid xml sitemap() of the navigation container. You already know this, but I&#8217;ve included a code sample of how to do this with the menu() method of the Navigation view helper for completeness.</p><p>Here&#8217;s a code sample:</p><blockquote><div
id="_mcePaste">&lt;!&#8211; left &#8211;&gt;</div><div
id="_mcePaste">&lt;div id=&#8221;left&#8221;&gt;</div><div
id="_mcePaste">&lt;?php echo $this-&gt;navigation()-&gt;menu(); ?&gt;</div><div
id="_mcePaste">&lt;/div&gt;</div><div
id="_mcePaste">&lt;!&#8211; /left &#8211;&gt;</div></blockquote><div>So there you have it. A nicely organised and easily configurable navigation system for your Zend Framework MVC Web Application. I hope you find this helpful. It sure was to me.</div><div><strong>References:</strong></div><div><ul><li><a
href="http://www.zendcasts.com" target="_blank">Zend Casts</a> Screen Cast on <a
href="http://www.zendcasts.com/zend_navigation-dynamically-creating-a-menu-a-sitemap-and-breadcrumbs/2009/06/" target="_blank">Zend_Navigation – creating a menu, a sitemap and breadcrumbs</a>.</li><li><a
href="http://framework.zend.com/manual/en/zend.navigation.html" target="_blank">Zend Navigation Manual</a>.</li></ul></div> ]]></content:encoded> <wfw:commentRss>http://www.rvdavid.net/zend_navigation-makes-writing-navigation-for-zf-sites-very-easy/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </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:42:09 -->