<?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</title> <atom:link href="http://www.rvdavid.net/tag/php/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>Unit Testing &amp; TDD Keeps you focussed and gives you Peace of mind</title><link>http://www.rvdavid.net/unit-testing-tdd-keeps-you-focussed-and-gives-you-peace-of-mind/</link> <comments>http://www.rvdavid.net/unit-testing-tdd-keeps-you-focussed-and-gives-you-peace-of-mind/#comments</comments> <pubDate>Mon, 11 Jan 2010 14:24:54 +0000</pubDate> <dc:creator>rvdavid</dc:creator> <category><![CDATA[Web Development]]></category> <category><![CDATA[Fast 15]]></category> <category><![CDATA[php]]></category> <category><![CDATA[unit testing]]></category><guid
isPermaLink="false">http://www.rvdavid.net/?p=277</guid> <description><![CDATA[Most of my day was spent on developing the User Model Layer for an application that my team and I are currently developing at DevProducts HQ. I&#8217;d like to briefly talk about how we are using TDD and discuss one major benefit that this method of development provides for my team and I during development. [...]]]></description> <content:encoded><![CDATA[<p>Most of my day was spent on developing the User Model Layer for an application that my team and I are currently developing at DevProducts HQ. I&#8217;d like to briefly talk about how we are using TDD and discuss one major benefit that this method of development provides for my team and I during development.</p><p>While TDD has many benefits, my favourite is that it helps to keep me and the other developers on my team focussed on the components we have chosen to work on. Not only that, but it helps us focus on the task at hand as it forces us to think about each unit of the component and write it so that it _can_ be tested &#8211; as much as I&#8217;d like to expand on TDD itself, for this post, I&#8217;m just going to explain how it could help you keep focussed.</p><h3>How does it keep you focussed?</h3><p><span
id="more-277"></span></p><p>Let&#8217;s take creating a user login form as an example. One of the key requirements for the application we are developing is to have a password protected administration area which requires a predefined username and password to enter. The ACL is dynamic, so an administrator has to have the ability to list, add, edit and delete users. Once the user is added, they can use the login form to identify themselves to the system with the username and password assigned to them by the administrator.</p><p>Now just as I&#8217;m typing this, a flood of components that will need to be written is coming to me - you&#8217;ll need the following:</p><ul><li>You&#8217;ll need, of course, the Login Form itself.</li><li>A User Model, then the corresponding validation which will be taken care of via the form, but still you need to make sure that this ties in with everything.</li><li>User Type and User Status Models.</li><li>You&#8217;ll need an ACL Component.</li><li>I like to Access to all this model functionality is simplified via a class that&#8217;s been coined as the Model Service class.</li><li>You&#8217;ll need to Create Controller Actions.</li><li>Along with Corresponding View Scripts.</li></ul><p>How are you going to keep your focus with so many parts? You start from one point (the controller), make a list and start writing the application and start with &#8220;code&#8221;, &#8220;see if it works&#8221;, &#8220;next thing&#8221; kinda fashion. But what happens when you need to add something, you get called away from your desk for whatever reason (clients, ad hoc meetings etc)?</p><p>You will lose your train of thought, spend at least 20 &#8211; 30 minutes to get back to where you were and ultimately lose your focus &#8211; things are a little harder to picture. With Test Driven Development or TDD for short, we develop applications by writing the test first &#8211; the test is named as close to the business requirement as possible (such as &#8220;TestCanFindUserByUsernameAndPassword&#8221;), we write code to pass the test, then we write the next test.</p><p>I find that this keeps me focussed because when I step away from my desk or move onto other things during the day, I can come back to my unit test, and continue working from that point forward. I can focus on the task at hand since my only goal is to pass the last test I created before writing the next test. Before I know it, I&#8217;ve run out of tests to write and I&#8217;ve made several assertions on results and expectations.</p><h3>Peace of Mind with TDD</h3><p>There&#8217;s also the peace of mind factor &#8211; which is my second favourite benefit. You have peace of mind because you can be a little more confident that your code is working when you use TDD. This is because you have tested your code unit by unit as you wrote the application in iterations. Rather than writing the application as a whole, then testing each publicly accessible component over and over again.</p><p>Now I know that there are days when you&#8217;re just &#8220;In the Zone&#8221; and you will know where all this stuff is, what to do, how this all ties in to the point where you do a functional test and you achieve absolute perfection! But there is a reason that this is regarded as a &#8220;marveled feat&#8221; because it&#8217;s almost impossible to do and you need everything to go your way (no distractions, stars have to be aligned etc). But know this, even though you have developed the app and have tested a single method of usage, what&#8217;s to say that when it&#8217;s used in other ways it will still work?</p><p>I know this from experience and the following will happen to you:</p><ul><li>You will miss things.</li><li>You go over things several times and even then still, you will miss things.</li><li>You do lengthy functional tests over and over again because you&#8217;re paranoid (you&#8217;ve missed things before).</li><li>You get the &#8220;that was too easy&#8221; feeling and start checking again.</li><li>Finally, there&#8217;s the part where you think you&#8217;ve got it all submitted it to the client and then they find that you&#8217;ve missed things.</li></ul><p>Trust me, regardless of how good a developer you are, you are susceptible to missing things. I had a junior one time who seemed to be a bright kid. Knew a lot and had the some work ethic. The developer would make up stories about friends of theirs who code in this way and write &#8220;perfect code&#8221; &#8211; I&#8217;d shrug it off and simply refute that they haven&#8217;t tested enough.</p><p>Funny enough, the more we worked together, the more I noticed that this junior worked like the fabled &#8220;perfect code&#8221; developer, but when tested enough times, bugs upon bugs upon bugs would start cropping up &#8211; thankfully this relationship is in the past which is where it will stay. There will be no way I&#8217;d be recruiting this person again. This person does not inspire confidence and really gives me no peace of mind.</p><p>If the junior dev at least knew Unit Testing, then I&#8217;d sleep easier knowing that the code they wrote is backed up by Unit Tests. I know the units of the components developed works as intended and changes can be changes can be tested easily.</p><p>Anyway, I guess this fast 15 has again gone way over time. So I&#8217;ll wrap it up here. See you on tomorrow&#8217;s fast 15.</p><h3>Want to know about TDD?</h3><p>I understand that this is a very general post about TDD, so if you would like to know more check out the following links:</p><ul><li><a
title="Gives a more detailed overview of TDD" href="http://en.wikipedia.org/wiki/Test-driven_development" target="_blank">Test Driven Development</a> on Wikipedia.</li><li><a
title="Unit Testing with the Zend Framework with Zend_Test and PHPUnit" href="http://www.zendcasts.com/unit-testing-with-the-zend-framework-with-zend_test-and-phpunit/2009/06/" target="_blank">Unit Testing Screencast</a> at <a
title="Great source for quality Screencasts for Zend Framework related topics" href="http://www.zendcasts.com/" target="_blank">Zend Casts</a>.</li><li>The <a
title="PHPUnit by Sebastian Bergmann" href="http://www.phpunit.de/" target="_blank">PHPUnit Unit Testing Framework</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://www.rvdavid.net/unit-testing-tdd-keeps-you-focussed-and-gives-you-peace-of-mind/feed/</wfw:commentRss> <slash:comments>3</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>The Default Virtuemart Theme is a piece of $***!</title><link>http://www.rvdavid.net/the-default-virtuemart-theme-is-a-piece-of/</link> <comments>http://www.rvdavid.net/the-default-virtuemart-theme-is-a-piece-of/#comments</comments> <pubDate>Sat, 30 Aug 2008 06:11:31 +0000</pubDate> <dc:creator>rvdavid</dc:creator> <category><![CDATA[Rants]]></category> <category><![CDATA[joomla]]></category> <category><![CDATA[php]]></category><guid
isPermaLink="false">http://blog.rvdavid.net/the-default-virtuemart-theme-is-a-piece-of/</guid> <description><![CDATA[There I&#8217;ve said it, I&#8217;ve spent the most part of today and my afternoon yesterday theming VM. I thought, hey there&#8217;s a default template here, I&#8217;ll just modify that&#8230; Several hours later, I&#8217;m bumping into inline styles, redundant div nesting and crappy css! FFS I just wanted to change a couple of defaults! VM team! [...]]]></description> <content:encoded><![CDATA[<p>There I&#8217;ve said it, I&#8217;ve spent the most part of today and my afternoon yesterday theming VM. I thought, hey there&#8217;s a default template here, I&#8217;ll just modify that&#8230;</p><p>Several hours later, I&#8217;m bumping into inline styles, redundant div nesting and crappy css! FFS I just wanted to change a couple of defaults! VM team! Please update your default template to use semantic mark up!!!! I can&#8217;t put it anyother way&#8230; The default virtuemart theme is a piece of $***.</p><p><span
id="more-114"></span>Anyway, perhaps I&#8217;ll go ahead and create a skeleton theme with nicely  structured html documents and clean CSS&#8230; The problem is, as you may have guessed, I never have any free time nowadays.  If you&#8217;ve found one, please feel free to link feed me <img
src='http://www.rvdavid.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>&#8211; OT &#8211;</p><p>Oh yeah and just an update on life as requested by some of my readers- it&#8217;s good, very busy&#8230; having a great time living it! Sorry I&#8217;ve not had the time to reply. <img
src='http://www.rvdavid.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>&#8211; /OT &#8211;</p> ]]></content:encoded> <wfw:commentRss>http://www.rvdavid.net/the-default-virtuemart-theme-is-a-piece-of/feed/</wfw:commentRss> <slash:comments>2</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> <item><title>Stay away from Bloated Class Methods, actually, bloated ANYTHING!</title><link>http://www.rvdavid.net/stay-away-from-bloated-class-methods-actually-bloated-anything/</link> <comments>http://www.rvdavid.net/stay-away-from-bloated-class-methods-actually-bloated-anything/#comments</comments> <pubDate>Fri, 14 Mar 2008 13:38:40 +0000</pubDate> <dc:creator>rvdavid</dc:creator> <category><![CDATA[PHP Programming]]></category> <category><![CDATA[php]]></category><guid
isPermaLink="false">http://blog.rvdavid.net/stay-away-from-bloated-class-methods-actually-bloated-anything/</guid> <description><![CDATA[Why are there so many examples of bloated PHP methods out there?! I see a lot of bloated methods being used in examples through sites like phpclasses.org and a very large chunk of a project I&#8217;ve recently picked up which a few developers have worked on. Guys! remember! There is no good reason to bloat [...]]]></description> <content:encoded><![CDATA[<p><strong>Why are there so many examples of bloated PHP methods out there?!</strong> I see a lot of bloated methods being used in examples through sites like phpclasses.org and a very large chunk of a project I&#8217;ve recently picked up which a few developers have worked on. Guys! remember!  There is no good reason to bloat your methods to over 10-20 lines long and on the rare occasions that you do exceed 10 &#8211; 20 lines it would be more the exception to the rule as opposed to being the rule itself!</p><p>Let&#8217;s not forget what classes and its methods are supposed to be: <strong>Classes are blueprints for specialist components</strong> and their methods are singular actions  which address one to a few (2 &#8211; 3 at most!) procedures at a time whether it be through the use of other classes or just through simple logic!</p><p><span
id="more-96"></span></p><p><strong>DO YOURSELF A FAVOUR!</strong> Write smaller specific class methods. I know it&#8217;s hard to get your head around. When I initially started doin&#8217; it the right way, I thought that it was &#8220;fragmenting&#8221; the logic which seemed counter productive at the time, but with practice, you will find that encapsulating logic into small methods _AT THE RIGHT PLACES_ actually makes more sense than putting a whole chunk of logic in the one method.</p><p>Think about it &#8211; it&#8217;s the amateur spaghetti coder within you that&#8217;s trying to shove in all that logic into the one method &#8211; think back to when you first learnt how to program! Cramming all this logic into the one method is the same as the time you were doing with a single PHP page that grew to 2000 lines, a bloated function, an abused case statement or all that SQL you placed in the view layer and said that it was right because it&#8217;s convenient &#8211; It&#8217;s saying &#8220;I think we should do it this way because it&#8217;s easier&#8230; well for me it&#8217;s easier anyway&#8230;&#8221;</p><p>What will happen if you keep creating bloated methods is that as your code &#8220;grows&#8221; (into a monster), is that it will be harder and harder to maintain and test each unit of code because they&#8217;ve become so big!</p><p>&#8220;It&#8217;s not so hard, I know exactly where I put my code&#8230;&#8221; you say to me as you look over your shoulder tapping away at your giant method.</p><p>Let&#8217;s see you do that in 2 &#8211; 3 months time _after_ it&#8217;s released and we find some bugs or asking you to make a change.  The number of changes then become an issue &#8211; instead of weeks or days you&#8217;re thinking months and semesters.</p><p>&#8220;You&#8217;re making too many changes! This is going to be hard to do. Well, not hard to do but time consuming.&#8221;  You reason as you mess around with your search and replace and write a list for yourself on the whiteboard. How is it my fault that the crappy code you wrote is rigid and brittle?</p><p>Expect change and expect them occuring in random! Write code that is easy to follow and is straight forward. Documentation will not cover everything and it&#8217;s crazy to say that it does &#8211; I don&#8217;t want to spend time writing up sentences of instructions on how to use a method.</p><p>Writing smaller methods and semantically refactoring your bloated code (classes and methods) into neat semantic basic OOP principle following units is the key. nice encapsulation promotes readability and all that, but that&#8217;s for a discussion for another time.</p><p>To conclude, I&#8217;d like to issue a word of caution that&#8217;s somewhat unrelated to the post (I&#8217;ve said what I had to say), but brings up some recent memories &#8211; if someone argues that you should follow &#8220;convenience&#8221; over &#8220;convention&#8221;, you should get rid of them ASAP. They&#8217;ll corrupt your project&#8217;s codebase with their convenience code and come up with terrible ways of doing things.</p><p>Once they leave, you will have to deal with the mess they left behind and _that_ is a pain in the be-hind!</p> ]]></content:encoded> <wfw:commentRss>http://www.rvdavid.net/stay-away-from-bloated-class-methods-actually-bloated-anything/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>Execute Linux commands in PHP by using backticks</title><link>http://www.rvdavid.net/execute-linux-commands-in-php-by-using-backticks/</link> <comments>http://www.rvdavid.net/execute-linux-commands-in-php-by-using-backticks/#comments</comments> <pubDate>Sat, 12 Jan 2008 14:29:25 +0000</pubDate> <dc:creator>rvdavid</dc:creator> <category><![CDATA[General Notes]]></category> <category><![CDATA[Linux]]></category> <category><![CDATA[php]]></category><guid
isPermaLink="false">http://blog.rvdavid.net/execute-linux-commands-in-php-by-using-backticks/</guid> <description><![CDATA[You can execute linux commands within a php script &#8211; all you have to do is put the command line in backticks (`). Recently, I had to upload an archive to a server which did not allow ssh. For files that I need to transfer, I just package them up in a neat archive and [...]]]></description> <content:encoded><![CDATA[<p>You can execute linux commands within a php script &#8211; all you have to do is put the command line in backticks (`).</p><p>Recently, I had to upload an archive to a server which did not allow ssh. For files that I need to transfer, I just package them up in a neat archive and transfer the archive file via scp. Not having ssh access however, I uploaded the archive file via ftp and created a script which extracts the file the file looks like the following:<br
/> <span
id="more-87"></span></p><pre lang="php">
&lt;?php
#extractarchive.php
echo `tar -xvfz somearchive.tar.gz`;
?&gt;
</pre><p>Upon loading up &#8220;extractarchive.php&#8221;, I can see the output of the tar command through the browser. I did this by using the echo function on the backticked command line &#8211; this is not necessary for the backticked command to be executed by php.</p><p>Of course, the PHP file will need to have the necessary permissions to execute commands and as always, proceed with caution. I myself do not like doing things this way, I&#8217;ve used it in the past as a last resort. But if you ever need to do something like this, at least you know that this can be done with PHP.</p> ]]></content:encoded> <wfw:commentRss>http://www.rvdavid.net/execute-linux-commands-in-php-by-using-backticks/feed/</wfw:commentRss> <slash:comments>12</slash:comments> </item> <item><title>Classes &amp; Examples Sub-Category</title><link>http://www.rvdavid.net/classes-examples-sub-category/</link> <comments>http://www.rvdavid.net/classes-examples-sub-category/#comments</comments> <pubDate>Wed, 05 Dec 2007 13:22:58 +0000</pubDate> <dc:creator>rvdavid</dc:creator> <category><![CDATA[Announcements]]></category> <category><![CDATA[beginners]]></category> <category><![CDATA[php]]></category> <category><![CDATA[Web Development]]></category><guid
isPermaLink="false">http://blog.rvdavid.net/classes-examples-sub-category/</guid> <description><![CDATA[I&#8217;ve created a &#8220;Classes &#38; Examples&#8221; sub category for PHP. This category will be different from actual Design Patterns in a way that these will be more practical examples which you can modify and use in your own code base (all I ask is that you leave my name somewhere in the credits). The Posts [...]]]></description> <content:encoded><![CDATA[<p>I&#8217;ve created a &#8220;Classes &amp; Examples&#8221; sub category for PHP. This category will be different from actual Design Patterns in a  way that these will be more practical examples which you can modify and use in your own code base (all I ask is that you leave my name somewhere in the credits).</p><p>The Posts I will be making in the &#8220;Classes &amp; Examples&#8221; Sub-Category will be formatted in the following way:</p><p><span
id="more-82"></span></p><ul><li><strong>Problem: </strong>This is a short description of the problem that the PHP Class or Example will be solving.</li><li><strong>Class Name: </strong>The name of the PHP class.</li><li><strong>Responsibilities</strong>: The responsibilities of the PHP class.</li><li><strong>Collaborators:</strong> This lists the classes that interact with the PHP Class I will be using in the example.</li><li><strong>Code:</strong> What good is an example without any code?</li><li><strong>Considerations &amp; Conclusion:</strong> This part of the post covers things that should be considered either when developing or using the class or code example.</li></ul><p>As you can see, I will be trying to follow a specific format. I have some pretty big plans for this section, I hope you will find it as useful as I intend it to be.</p><p>regards.</p> ]]></content:encoded> <wfw:commentRss>http://www.rvdavid.net/classes-examples-sub-category/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 4/11 queries in 0.029 seconds using disk

Served from: www.rvdavid.net @ 2010-09-09 00:49:58 -->