<?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; PHP Programming</title> <atom:link href="http://www.rvdavid.net/category/web-development/php-programming/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> <item><title>Started Draft Post on Zend Framework, Doctrine &amp; PHPUnit Setup</title><link>http://www.rvdavid.net/started-draft-post-on-zend-framework-doctrine-phpunit-setup/</link> <comments>http://www.rvdavid.net/started-draft-post-on-zend-framework-doctrine-phpunit-setup/#comments</comments> <pubDate>Wed, 13 Jan 2010 12:23:41 +0000</pubDate> <dc:creator>rvdavid</dc:creator> <category><![CDATA[Zend Framework]]></category> <category><![CDATA[Fast 15]]></category><guid
isPermaLink="false">http://www.rvdavid.net/?p=289</guid> <description><![CDATA[Today as I unit tested my view scripts using asertXpath() via Zend_Test, I was thinking how far along I&#8217;ve come from writing notes whilst reading books on what the difference between Aggregation and Composition is, then posting confused questions on the Advanced PHP forum at SitePoint. People are very generous with information and happily help [...]]]></description> <content:encoded><![CDATA[<p>Today as I unit tested my view scripts using asertXpath() via Zend_Test, I was thinking how far along I&#8217;ve come from writing notes whilst reading books on what the difference between Aggregation and Composition is, then posting confused questions on the Advanced PHP forum at SitePoint. People are very generous with information and happily help out &#8211; they just give and give.</p><p><span
id="more-289"></span></p><p>I, on the other hand, did nothing but take and take &#8211; even to this point &#8211; so now I decided that one way to give back was to write a post on how to set up the Zend Framework complete with a model layer that I am going to be proposing. This should be interesting seeing as I&#8217;ve only _just_ managed to implement a Model Service layer which uses Doctrine ORM as a means to connect to the database.</p><p>I&#8217;ll also provide source code and will host it on github or google. What I found was that even though there was a lot of resources out there on how to integrate Zend Frameowk, Doctrine and PHPUnit on your devbox, some were a little out dated and some were a little unclear leaving me to feel my way around.</p><p>SO what I&#8217;m going to try and do is write something that can be used as a skeleton for anyone who may want to just knuckle down and hit the ground running. Not that you can&#8217;t already with the current Zend QuickStart, but I don&#8217;t think that I&#8217;m the only one who had problems getting this all to work so my target audience for this type blog post series are developers who have just discovered Zend Framework, Doctrine and Unit Testing and would like to have some references to poke around.</p><p>I guess that&#8217;s my thing for today. I&#8217;ll spend some hours on making sure it&#8217;s comprehensive enough to use as a how-to and present solutions on how I got around certain things such as the prerequisite to have Aggressive Model Autoloading for doctrine when in the Unit Testing Command line which uses Doctrine-CLI to refresh tables etc.</p><p>It won&#8217;t be tomorrow, but it will be done during the following weeks. I&#8217;ll be in touch.</p> ]]></content:encoded> <wfw:commentRss>http://www.rvdavid.net/started-draft-post-on-zend-framework-doctrine-phpunit-setup/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>How would you handle this? &#8211; Service Layer slowly getting polluted (or so it seems)!</title><link>http://www.rvdavid.net/how-would-you-handle-this-service-layer-slowly-getting-polluted-or-so-it-seems/</link> <comments>http://www.rvdavid.net/how-would-you-handle-this-service-layer-slowly-getting-polluted-or-so-it-seems/#comments</comments> <pubDate>Tue, 20 Oct 2009 15:02:07 +0000</pubDate> <dc:creator>rvdavid</dc:creator> <category><![CDATA[PHP Programming]]></category><guid
isPermaLink="false">http://blog.rvdavid.net/?p=168</guid> <description><![CDATA[Just going through the motions here using Zend Framework and an implementation of Service Layer and Domain Model to form my domain layer. I must admit &#8211; I thought I had made a break through, but alas, more analysis paralysis. I&#8217;m finding that I&#8217;m abusing the accessiblity of the Service Layer. Here&#8217;s an example: I&#8217;ve [...]]]></description> <content:encoded><![CDATA[<p>Just going through the motions here using Zend Framework and an implementation of Service Layer and Domain Model to form my domain layer.</p><p>I must admit &#8211; I thought I had made a break through, but alas, more analysis paralysis.</p><p>I&#8217;m finding that I&#8217;m abusing the accessiblity of the Service Layer.</p><p>Here&#8217;s an example:</p><ul><li>I&#8217;ve got an application which manages users.</li><li>I have a User Model and have User Service as the pivot point where application logic gets ported to to business logic.</li></ul><p><span
id="more-168"></span></p><p>The User Service class provides the following functionality:</p><ul><li>CRUD (Create, Read, Update and Delete) which pretty much proxies to the Model.</li><li>Also, the Service layer looks after Authentications</li><li>and Authorisation.</li></ul><p>All pretty straight forward, at this point. Of course you&#8217;ll also have:</p><ul><li>A Form factory in the UserService class as well as</li><li>a List method which returns an assoc array of mutiple results based on criteria.</li></ul><p>However, what would you do in situations where the client has requested for the<strong> Ability to update several records via a CSV import.</strong></p><p>I thought hey, ok, I&#8217;ll:</p><ul><li>Add a &#8220;get Upload Update File&#8221; form&#8230;</li><li>Then I&#8217;ll add an &#8220;Upload Method&#8221; to process the upload,</li><li>I need to delete this file also &#8211; now I&#8217;ll add a &#8220;delete file&#8221; method,</li><li>More thinking brought on I need to centralise file name creation so that ensure that I am only using one name.</li><li>I&#8217;m using a csvreadstore to read the csv file for review &#8211; so I need to have a &#8220;readstore&#8221; method for the csv file.</li><li>I&#8217;ll also need to validate this file</li><li>FInally, I need to massage the data from the CSV into my domain model and either update one by one by one or update it all as a big group.</li></ul><p>But this will leave me with an extremely heavy service layer and a somewhat thin Model object.</p><p>I don&#8217;t know what to do &#8211; I can do it both ways, but it&#8217;s just not blatantly clear as to which direction I should be pushing this to.</p><p>What would you do as an OOP programmer? Can you crack this little dillema I&#8217;m having? Am I heading in the right direction? Should I create a new Service layer called UpdateUsersService (which of course seems like a bad idea to me).</p><p>I&#8217;m open to feedback &#8211; where do you think I should go?</p> ]]></content:encoded> <wfw:commentRss>http://www.rvdavid.net/how-would-you-handle-this-service-layer-slowly-getting-polluted-or-so-it-seems/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Test Results on Memory Usage of Zend Framework and Doctrine with APC</title><link>http://www.rvdavid.net/test-results-on-memory-usage-of-zend-framework-and-doctrine-with-apc/</link> <comments>http://www.rvdavid.net/test-results-on-memory-usage-of-zend-framework-and-doctrine-with-apc/#comments</comments> <pubDate>Sat, 10 Oct 2009 05:55:46 +0000</pubDate> <dc:creator>rvdavid</dc:creator> <category><![CDATA[PHP Programming]]></category><guid
isPermaLink="false">http://blog.rvdavid.net/?p=163</guid> <description><![CDATA[After investigating a recommendation to use Doctrine by a fellow blogger, Brian at Real of Zod, I have decided to run with Doctrine as my Domain Model in Zend Framework projects. The thing is, if I&#8217;m going to commit to this, I need to know that applications I build in the future with the Zend [...]]]></description> <content:encoded><![CDATA[<p>After investigating a recommendation to use Doctrine by a fellow blogger, <a
title="Realm of Zod Blog" href="http://blog.realmofzod.com/" target="_blank">Brian at Real of Zod</a>, I have decided to run with Doctrine as my Domain Model in Zend Framework projects. The thing is, if I&#8217;m going to commit to this, I need to know that applications I build in the future with the Zend Framework while using Doctrine as an integral part of the Model layer will not take performance hits from things like memory usage.</p><p>With Doctrine doing a _lot_ of magic, I thought that this would be something that I wanted to see for myself.</p><p><strong>4MB Memory to execute a simple Query?!?! Ffffff#$#!!!!</strong></p><p>A quick google search took me to a Question posted on StackOverflow about <a
href="http://stackoverflow.com/questions/1412762/doctrine-query-memory-usage/1547135#1547135" target="_blank">Doctrine Memory Usage</a>. The concerned OP was asking if he had a server misconfiguration or if this was normal for Doctrine to be using so much memory for a simple query. He posted a 4MB difference in Peak Memory Usage between the start of the request before the Doctrine Query was executed and after the Doctrine Query was executed. After reading that, I was a little nervous.</p><p><span
id="more-163"></span></p><p><strong>Use Opcode Caching to reduce Memory Usage.</strong></p><p>There were a couple of answers and comments one of the answers came from Doctrine&#8217;s own romanb (I think?) specifying that you _need_ opcode caching if you&#8217;re going to be using something the size of Doctrine (and Zend Framework for that matter).</p><p>Similar to what the OP at StackOverflow did, I created a simple test which measures peak memory usage when using Doctrine from within the Zend Framework.</p><p>Be warned however, that this is not a real benchmark. All this is testing is what memory usage is using the simplest of simplest operations. In this case, I created a query which pulls one record from the Database.</p><p><strong>Here are the details. </strong></p><p>The Controller I used for this quick test:</p><blockquote><p>&lt;?php</p><p>class IndexController<br
/> extends Zend_Controller_Action<br
/> {<br
/> // with doctrine set up and everything<br
/> /**<br
/> *<br
/> * @return unknown_type<br
/> */<br
/> public function memoryUsageTestAction()<br
/> {<br
/> $this-&gt;_echo_memory_usage();<br
/> $q = Doctrine_Query::create()<br
/> -&gt;from(&#8216;Default_Model_User u&#8217;)<br
/> -&gt;where(&#8216;u.ID = ?&#8217;, 1);</p><p>$result = $q-&gt;fetchOne();<br
/> echo $result['FirstName'] . &#8216; &#8216; .$result['LastName']. &#8216;&lt;br /&gt;&#8217;;</p><p>$this-&gt;_echo_memory_usage();<br
/> exit;<br
/> }</p><p>/**<br
/> * Function from: http://www.php.net/manual/en/function.memory-get-usage.php<br
/> * @return unknown_type<br
/> */<br
/> protected function _echo_memory_usage() {<br
/> $mem_usage = memory_get_usage(true);</p><p>if ($mem_usage &lt; 1024)<br
/> echo $mem_usage.&#8221; bytes&#8221;;<br
/> elseif ($mem_usage &lt; 1048576)<br
/> echo round($mem_usage/1024,2).&#8221; kilobytes&#8221;;<br
/> else<br
/> echo round($mem_usage/1048576,2).&#8221; megabytes&#8221;;<br
/> echo &#8220;&lt;br/&gt;&#8221;;<br
/> }<br
/> }</p></blockquote><p><strong>Result without APC:</strong></p><blockquote><p>10.25 megabytes<br
/> RV David<br
/> 16.5 megabytes</p></blockquote><p><strong>Result with APC:</strong></p><blockquote><p>3 megabytes<br
/> RV David<br
/> 4.25 megabytes</p></blockquote><p><strong>This is with the following APC configuration:</strong></p><blockquote><p>apc.shm_size = 30<br
/> apc.ttl = 7200<br
/> apc.user_ttl = 7200<br
/> apc.mmap_file_mask = /tmp/apc.XXXXXX</p><p>apc.shm_segments = 1<br
/> apc.optimization = 0<br
/> apc.num_files_hint = 1000</p></blockquote><p>As you can see, there&#8217;s a big difference &#8211; chopped ZF Memory Peak Usage (my configuration anyway) by about 65%-70% and Peak Usage with a Doctrine call to the Database by about 75%.</p> ]]></content:encoded> <wfw:commentRss>http://www.rvdavid.net/test-results-on-memory-usage-of-zend-framework-and-doctrine-with-apc/feed/</wfw:commentRss> <slash:comments>11</slash:comments> </item> <item><title>Zend Framework Model &#8211; Research into Possible Domain Model Solutions</title><link>http://www.rvdavid.net/zend-framework-model/</link> <comments>http://www.rvdavid.net/zend-framework-model/#comments</comments> <pubDate>Wed, 30 Sep 2009 15:34:46 +0000</pubDate> <dc:creator>rvdavid</dc:creator> <category><![CDATA[PHP Programming]]></category><guid
isPermaLink="false">http://blog.rvdavid.net/?p=159</guid> <description><![CDATA[I&#8217;ve managed to spend some time sitting back and looking over some of hte projects I&#8217;ve worked on for the past year or so with the Zend Framework and decided that it was finally time to look into something that has always bugged me since the old Cubix Framework days. That was the lack of [...]]]></description> <content:encoded><![CDATA[<p>I&#8217;ve managed to spend some time sitting back and looking over some of hte projects I&#8217;ve worked on for the past year or so with the Zend Framework and decided that it was finally time to look into something that has always bugged me since the old Cubix Framework days.</p><p>That was the lack of decoupling of my Model layer from the View and Controller layers of my MVC projects. Don&#8217;t get me wrong, the applications we&#8217;ve written work and work well, but the perfectionist in me simply just refuses to stop trying to mentally refactor old projects.</p><p>From the time I had first conceptualised the our in-house MVC framework: Cubix and this is before switching to Zend,  something that has left me in Analysis paralysis is the Model layer.</p><p>I mean, most things I&#8217;ve read usually mention the Model layer as a representation of your applications business logic, but this is left wide open to interpretation. The difficult thing here is, that because the business logic is so specific to projects, there&#8217;s no real way of explaining it aside from some really basic examples which turn out to be the equivallent of a Javascript example of: &#8220;Hello World.&#8221;</p><p><span
id="more-159"></span></p><p>Not very useful, examples leave a lot of details out &#8211; because there&#8217;s no real way of dishing out a good example. Even the Zend Framework&#8217;s guestbook example in their Quickstart is a little thin.</p><p>Starting my research, I googled the term <a
title="Googled: Zend Framework Model Tutorial" href="http://www.google.com.au/#hl=en&amp;source=hp&amp;q=zend+framework+model+tutorial&amp;btnG=Google+Search&amp;meta=&amp;aq=f&amp;oq=zend+framework+model+tutorial&amp;fp=c0071818276efd4" target="_blank">zend framework model tutorial</a> and one of the entries that piqued my interest was a post by brandon from realm of zod titled: <a
title="Brian from Realm of Zod posted: Domain Model Programming With the Zend Framework" href="http://blog.realmofzod.com/2009/04/03/domain-model-programming-with-the-zend-framework/" target="_blank">Domain Model Programming With the Zend Framework</a> which talks about using <a
title="Doctrine Project: PHP Object Relational Mapper" href="http://www.doctrine-project.org/" target="_blank">Doctrine</a> ORM instead of <a
title="Zend Db Table: Table Data Gateway" href="http://framework.zend.com/manual/en/zend.db.table.html" target="_blank">Zend DB Table</a>&#8216;s <a
title="Martin Fowler's Table Data Gateway" href="http://martinfowler.com/eaaCatalog/tableDataGateway.html" target="_blank">Table Data Gateway</a> implementation.</p><p>I wasn&#8217;t so interested in Doctrine, so I just skimmed past the examples, but he did mention a few links, one link was to <a
title="Matthe Weier O'Phinney" href="http://weierophinney.net/matthew/" target="_blank">Matthew Weier O&#8217;Phinney&#8217;s</a> blog post on <a
title="Matthe Weier O'Phinney: Model Infrastructure" href="http://weierophinney.net/matthew/archives/202-Model-Infrastructure.html" target="_blank">Model Infrastructure</a> &#8211; here, Matthew talks about the implementation of the <a
title="Domain Model Design Pattern: Martin Fowler" href="http://martinfowler.com/eaaCatalog/domainModel.html" target="_blank">Domain Model Design Pattern </a>and talks about having a Gateway to the Domain using the Gateway pattern from Martin Fowler&#8217;s PoEAA (ok &#8211; you get the picture, I&#8217;ll stop hyper linking).</p><p>I thought: Great! So we use the Domain Model Design Pattern (as the model layer) to represent business logic, then create an access point or gateway if you will with a simple API that the model&#8217;s client&#8217;s can use to make the model do it&#8217;s thing!</p><p><strong>As oppsed to to how I used to do it </strong>which is use the model class as the access point for Business Data and Process.</p><p>I browsed through the comments,  past all the questions and onto comment #34 where the commen(ta?)tor asks about why shouldn&#8217;t we just stick domain login in Zend_Db_Table_Row_Abstract and how muddying the Domain Model by making it aware of the persistence layer (I&#8217;m guessing this means database) is equally wrong &#8211; why we shouldn&#8217;t extend Zend_Db_Table_Row_Abstract is a given, but I thought that he did have a point when he mentioned that persistence and business logic is just as bad.</p><p><strong>Enter the Service Layer</strong></p><p>Poster #34 added a link to Angry Objects&#8217; one and only blog post: <a
title="lbrouwer: Angry Objects" href="http://www.angryobjects.com/2009/03/30/writing-robust-php-backends-with-zend-framework/" target="_blank">Writing Robust PHP Backends with Zend Framework</a> and just like that, it was clear. This is what I&#8217;ve been looking for all this time! Or so it seemed!</p><p><strong>Exit the Bloated Service Layer: The Method Described above is actually an Anti-pattern.<br
/> </strong></p><p>Further research then reveals that almost everything mentioned on Angry Object&#8217;s post, is what Martin Fowler talks about in 2003 on his Bliki: The <a
title="Anemic Domain Model Anti-Pattern." href="http://martinfowler.com/bliki/AnemicDomainModel.html" target="_blank">Anemic Domain Model anti-pattern</a>.</p><p><strong>What should happen now then?</strong></p><p>Well the night wasn&#8217;t all a loss &#8211; the Anemic Domain Model Anti-Pattern page on Martin Fowler&#8217;s Bliki actually explains what your Domain Models  and what Service Layers are actually for.</p><p>So armed with this knowledge, I&#8217;ll march forward and develop my next project using the Domain Model with a thin Service Layer &#8211; similar, if not identical to, what Matthew was talking about on his blog post on Model Infrastructure) as I go through this and if I find some more free time, I might post some code samples of how I&#8217;m going.</p><p>And so wraps up yet another night of R&amp;D &#8211; Interesting though, thought I had this licked. At least now, I have a few ideas as to which path to take. I&#8217;ll be downloading Matthews pastebin app to get some sample source code &#8211; should be interesting.</p> ]]></content:encoded> <wfw:commentRss>http://www.rvdavid.net/zend-framework-model/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Joomla!: How to hide the Administrator or Front end layout template</title><link>http://www.rvdavid.net/joomla-how-to-hide-the-administrator-or-front-end-layout-template/</link> <comments>http://www.rvdavid.net/joomla-how-to-hide-the-administrator-or-front-end-layout-template/#comments</comments> <pubDate>Tue, 21 Apr 2009 03:56:44 +0000</pubDate> <dc:creator>rvdavid</dc:creator> <category><![CDATA[General Notes]]></category> <category><![CDATA[joomla]]></category><guid
isPermaLink="false">http://blog.rvdavid.net/joomla-how-to-hide-the-administrator-or-front-end-layout-template/</guid> <description><![CDATA[It&#8217;s taken a good part of an hour trying to find how to disable the administrator or front end template for Joomla. So I thought I&#8217;d just make a post in an effort to turn this frustrated energy into something positive. To display only the contents of the view on the page without being framed [...]]]></description> <content:encoded><![CDATA[<p>It&#8217;s taken a good part of an hour trying to find how to disable the administrator or front end template for Joomla.<br
/> So I thought I&#8217;d just make a post in an effort to turn this frustrated energy into something positive.</p><p>To display only the contents of the view on the page without being framed by a template, the tmpl variable needs to be set to &#8220;component&#8221;.</p><p><span
id="more-131"></span></p><p>Something along the lines of having the following snippet in the controller method:<br
/> JRequest::setVar(&#8216;tmpl&#8217;, &#8216;component&#8217;);</p><p>Either that, or adding &#8220;&amp;tmpl=component&#8221; to the URL.</p><p>I remember doing it before, however it&#8217;s been a while.</p><p>All attempts at searching on how to do the above proved frustratingly impossible as the organic search results for google are filled with people asking how to &#8220;disable legacy&#8221; modes, &#8220;templates&#8221;, &#8220;modules&#8221;, &#8220;plugins&#8221;, how to make your joomla admin panel rock(!!!!) &#8211; not what I was looking for!</p><p>Anyway, it&#8217;s a rather simple, but not particulary obvious thing &#8211; I had to track down the code which I had written over 6 months ago to track that snippet down.</p><p>Hope this helps other Joomla! component developers <img
src='http://www.rvdavid.net/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /></p> ]]></content:encoded> <wfw:commentRss>http://www.rvdavid.net/joomla-how-to-hide-the-administrator-or-front-end-layout-template/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>Joomla 1.5.7 Security release is now available</title><link>http://www.rvdavid.net/joomla-157-security-release-is-now-available/</link> <comments>http://www.rvdavid.net/joomla-157-security-release-is-now-available/#comments</comments> <pubDate>Thu, 11 Sep 2008 21:33:59 +0000</pubDate> <dc:creator>rvdavid</dc:creator> <category><![CDATA[PHP Programming]]></category> <category><![CDATA[php]]></category><guid
isPermaLink="false">http://blog.rvdavid.net/joomla-157-security-release-is-now-available/</guid> <description><![CDATA[Joomla! has released the latest version of their Open Source Software. In a nutshell, the release contains fixes for 1 critical and 2 moderate vulnerabilities. The Developers urge all 1.5.x users to upgrade _now_ More details can be found on the official announcement: http://www.joomla.org/announcements/release-news/5212-joomla-157-security-release-now-available.html Find your update package here: http://joomlacode.org/gf/project/joomla/frs/?action=FrsReleaseBrowse&#38;frs_package_id=3947]]></description> <content:encoded><![CDATA[<p>Joomla! has released the latest version of their Open Source Software. In a nutshell, the release contains fixes for 1 critical and 2 moderate vulnerabilities.</p><p>The Developers urge all 1.5.x users  to upgrade _now_</p><p><span
id="more-118"></span></p><p>More details can be found on the official announcement: <a
href="http://www.joomla.org/announcements/release-news/5212-joomla-157-security-release-now-available.html" target="_blank">http://www.joomla.org/announcements/release-news/5212-joomla-157-security-release-now-available.html</a></p><p>Find your update package here: <a
href="http://joomlacode.org/gf/project/joomla/frs/?action=FrsReleaseBrowse&amp;frs_package_id=3947" target="_blank">http://joomlacode.org/gf/project/joomla/frs/?action=FrsReleaseBrowse&amp;frs_package_id=3947</a></p> ]]></content:encoded> <wfw:commentRss>http://www.rvdavid.net/joomla-157-security-release-is-now-available/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Security Alert for Joomla 1.5.x Users</title><link>http://www.rvdavid.net/security-alert-for-joomla-15x-users/</link> <comments>http://www.rvdavid.net/security-alert-for-joomla-15x-users/#comments</comments> <pubDate>Wed, 13 Aug 2008 22:50:02 +0000</pubDate> <dc:creator>rvdavid</dc:creator> <category><![CDATA[PHP Programming]]></category> <category><![CDATA[bugs]]></category> <category><![CDATA[joomla]]></category> <category><![CDATA[php]]></category><guid
isPermaLink="false">http://blog.rvdavid.net/security-alert-for-joomla-15x-users/</guid> <description><![CDATA[A security alert has been raised at the Joomla Developer site. A vulnerability has been found to exist in the &#8220;user&#8221; component of the popular OSS which allows attackers to forge a password reset. Joomla Developers have since developed a patch which is available from their website. Versions affected: 1.5 &#8211; 1.5.5 Solution: Download the [...]]]></description> <content:encoded><![CDATA[<p>A security alert has been raised at the Joomla Developer site. A vulnerability has been found to exist in the  &#8220;user&#8221; component of the popular OSS which allows attackers to forge a password reset. Joomla Developers have since developed a patch which is available from their website.</p><p><strong>Versions affected:</strong> 1.5 &#8211; 1.5.5<br
/> <strong>Solution:</strong> Download the patch and Upgrade to 1.5.6 -&gt; <a
href="http://developer.joomla.org/security/news/241-20080801-core-password-remind-functionality.html" target="_blank">http://joomlacode.org/gf/project/joomla/frs/</a></p><p>More details about this vulnerability can be found on the following URL:<br
/> <a
href="http://developer.joomla.org/security/news/241-20080801-core-password-remind-functionality.html" target="_blank">http://developer.joomla.org/security/news/241-20080801-core-password-remind-functionality.html</a></p> ]]></content:encoded> <wfw:commentRss>http://www.rvdavid.net/security-alert-for-joomla-15x-users/feed/</wfw:commentRss> <slash:comments>0</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 2/12 queries in 0.007 seconds using disk

Served from: www.rvdavid.net @ 2010-09-10 20:47:25 -->