<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Kanian77's Weblog</title>
	<atom:link href="http://kanian77.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://kanian77.wordpress.com</link>
	<description>MVC,PHP, and some more</description>
	<lastBuildDate>Thu, 04 Sep 2008 01:37:35 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='kanian77.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/dcbd50d4ee1839bfb48ecf3ff4d77642?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Kanian77's Weblog</title>
		<link>http://kanian77.wordpress.com</link>
	</image>
			<item>
		<title>MVC and The Web</title>
		<link>http://kanian77.wordpress.com/2008/09/04/vi-mvc-and-the-web/</link>
		<comments>http://kanian77.wordpress.com/2008/09/04/vi-mvc-and-the-web/#comments</comments>
		<pubDate>Thu, 04 Sep 2008 01:33:31 +0000</pubDate>
		<dc:creator>kanian77</dc:creator>
				<category><![CDATA[MVC and the web]]></category>
		<category><![CDATA[Add new tag]]></category>

		<guid isPermaLink="false">http://kanian77.wordpress.com/?p=25</guid>
		<description><![CDATA[MVC was originally applied in a desktop application environment where the application resides on the computer with wich the user is interacting.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kanian77.wordpress.com&blog=2054282&post=25&subd=kanian77&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="margin-bottom:0;" lang="fr-FR" align="left"><span style="color:#000000;"><span style="font-size:small;"><strong></strong>MVC was originally applied in a desktop application environment where the application resides on the computer with wich the user is interacting.</span></span></p>
<p style="margin-bottom:0;" lang="fr-FR" align="left"><span style="color:#000000;"><span style="font-size:small;">While interacting with a web application, the user is sending requests to a distant server through his browser (the client). The server possess the necessary ressources to respond to the user&#8217;s request. The user receives the server&#8217;s  response on its browser window.  Thus when developers wan to apply the MVC pattern to a web application, they have to take into consideration the client/server environment in which the application operates.</span></span></p>
<p style="margin-bottom:0;" align="left"><span lang="fr-FR"><span style="color:#000000;"><span style="font-size:small;"><span>We will cite</span><strong> </strong></span><span style="font-size:x-small;"><span style="font-family:Times New Roman,serif;">Lech MADEYSKI, Michał STOCHMIAŁEK</span></span></span></span><sup><span lang="fr-FR"><span style="font-size:x-small;"><span style="font-family:Times New Roman,serif;"><span style="color:#000000;"><a class="sdfootnoteanc" name="sdfootnote1anc" href="#sdfootnote1sym"><sup>1</sup></a></span></span></span></span></sup><span lang="fr-FR"><span style="font-size:xx-small;"><span style="font-family:Times New Roman,serif;"><span style="color:#000000;"> <strong>: </strong></span></span></span></span></p>
<p style="margin-bottom:0;" align="left"><em><span lang="fr-FR"><span style="font-size:small;"><span style="color:#000000;"> </span></span></span></em></p>
<ul>
<li><em><span lang="fr-FR"><span style="font-size:small;"><span style="color:#000000;"><span>The</span></span></span></span></em><em> HTTP protocol, the technological foundation of web applications, is stateless.</em></li>
<li><em>Each command is executed independently, without any knowledge of the commands that<br />
came before it.</em></li>
<li><em>Web application’s responsibility is to keep the state between requests.</em></li>
<li><em> Conversation between user and application can be initiated only by the user.</em></li>
<li><em>Control flow of web applications is driven by user requests. It usually consists of<br />
complex sequence of interactions between the user and server.</em></li>
</ul>
<p style="margin-bottom:0;" align="left">
<p><span style="font-style:normal;"><span lang="fr-FR"><span style="font-size:small;"><span style="font-family:Times New Roman,serif;"><span style="color:#000000;">A typical MVC application can be represented by this diagram</span></span></span></span></span><sup><span style="font-style:normal;"><span lang="fr-FR"><span style="font-size:small;"><span style="font-family:Times New Roman,serif;"><span style="color:#000000;"><a class="sdfootnoteanc" name="sdfootnote1anc" href="#sdfootnote1sym"><sup>2</sup></a></span></span></span></span></span></sup><a class="sdfootnotesym" name="sdfootnote1sym" href="#sdfootnote1anc"><br />
</a></p>
<p style="margin-bottom:0;" align="left">
<p style="margin-bottom:0;font-style:normal;" lang="fr-FR" align="left"><a href="http://kanian77.files.wordpress.com/2008/09/mvc.jpg"><img class="alignnone size-full wp-image-26" src="http://kanian77.files.wordpress.com/2008/09/mvc.jpg?w=375&#038;h=247" alt="" width="375" height="247" /></a></p>
<p style="margin-bottom:0;font-style:normal;" lang="fr-FR" align="left"><span style="color:#000000;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">There exist different solutions to using MVC in a web application. For example server side MVC or MVC/Model 2 will host the Controller, the View and the Model on the server.</span></span></span></p>
<p style="margin-bottom:0;font-style:normal;" lang="fr-FR" align="left">
<p style="margin-bottom:0;font-style:normal;" lang="fr-FR" align="left"><span style="color:#000000;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Server side MVC or  MVC/Model 2</strong></span></span></span></p>
<p style="margin-bottom:0;" align="left"><span style="font-style:normal;"><span lang="fr-FR"><span style="font-size:small;"><span style="font-family:Times New Roman,serif;"><span style="color:#000000;">The simplest way to use MVC in a web application is to put the Controller , the View and the Model  on the server. The user request will be transmitted by the web client as a request to the server that will pass it to the controller. The controller will interpret the user request as a command to the model ( CRUD operations). The controller will make the result of the operation available to the view. The view can then send a response to the web client for display. Here the client will be considered We can represent the process by the following diagram</span></span></span></span></span><sup><span style="font-style:normal;"><span lang="fr-FR"><span style="font-size:small;"><span style="font-family:Times New Roman,serif;"><span style="color:#000000;"><a class="sdfootnoteanc" name="sdfootnote1anc" href="#sdfootnote1sym"><sup>3</sup></a></span></span></span></span></span></sup></p>
<div><a href="http://kanian77.files.wordpress.com/2008/09/mvc_model21.jpg"><img class="alignnone size-full wp-image-28" src="http://kanian77.files.wordpress.com/2008/09/mvc_model21.jpg?w=425&#038;h=216" alt="" width="425" height="216" /></a></div>
<p style="margin-bottom:0;" lang="fr-FR" align="left"><span style="color:#000000;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">This approach  to adapte MVC to a web environment was  termed the MVC/Model 2 design pattern. </span></span></span></p>
<p style="margin-bottom:0;" align="left"><span lang="fr-FR"><span style="font-size:small;"><span style="font-family:Times New Roman,serif;"><span style="color:#000000;">On the Apache Struts website </span></span></span></span><sup><span lang="fr-FR"><span style="font-size:small;"><span style="font-family:Times New Roman,serif;"><span style="color:#000000;"><a class="sdfootnoteanc" name="sdfootnote1anc" href="#sdfootnote1sym"><sup>4</sup></a></span></span></span></span></sup><span lang="fr-FR"><span style="font-size:small;"><span style="font-family:Times New Roman,serif;"><span style="color:#000000;"> we can read:</span></span></span></span></p>
<p style="margin-bottom:0;" lang="fr-FR" align="left">
<p style="margin-bottom:0;" align="left"><em><span lang="fr-FR"><span style="font-size:small;"><span style="font-family:Times New Roman,serif;"><span style="color:#000000;"> In the MVC/Model 2 design pattern, application flow is mediated by a central Controller. The 	Controller delegates requests &#8211; in our case, HTTP requests &#8211; to an appropriate handler. The 	handlers are tied to a Model, and each handler acts as an adapter between the request and the 	Model. The Model represents, or encapsulates, an application&#8217;s business logic or state. Control 	is usually then forwarded back through the Controller to the appropriate View. The forwarding 	can be determined by consulting a set of mappings, usually loaded from a database or 	configuration file.</span></span></span></span></em><sup><em><span lang="fr-FR"><span style="font-size:small;"><span style="font-family:Times New Roman,serif;"><span style="color:#000000;"><a class="sdfootnoteanc" name="sdfootnote2anc" href="#sdfootnote2sym"><sup>5</sup></a></span></span></span></span></em></sup></p>
<p style="margin-bottom:0;font-style:normal;" lang="fr-FR" align="left"><span style="color:#000000;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">In fact with this pattern there are two communication cycles between the different components of the MVC triad that may arise:</span></span></span></p>
<ul>
<li>
<p style="margin-bottom:0;" align="left"><span style="font-style:normal;"><span lang="fr-FR"><span style="font-size:small;"><span style="color:#000000;">The 	<span style="font-family:Times New Roman,serif;">« User → Controller 	→ View → User » cycle in which the User interaction 	with the application is sent to the Controller as HTTP request. The 	Controller chooses the View to show to the User based on the request 	parameters.Finally it updates the View and returns it as a response 	to the User.</span></span></span></span></span></p>
</li>
<li>
<p style="margin-bottom:0;font-style:normal;" lang="fr-FR" align="left"><span style="color:#000000;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">The 	« User → Controller → Model → View → User » 	cycle in which the User interaction with the application is sent to 	the Controller as HTTP request. The Controller access the Model and 	updates it. It chooses the View to show to the User based on the 	request parameters.Finally it updates the View to reflect the Model 	change and returns it as a response to the User.</span></span></span></p>
</li>
</ul>
<p style="margin-bottom:0;" lang="fr-FR" align="left"><span style="color:#000000;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>Mixed client-side and server-side MVC</strong></span></span></span></p>
<p class="sdfootnote"><span><span lang="fr-FR"><span style="font-size:small;"><span style="font-family:Times New Roman,serif;"><span style="color:#000000;">The client processing power is used to carry on user data validation or view change that do not require accessing the server side Controller and/or Model.</span></span></span></span></span><sup><span><span lang="fr-FR"><span style="font-size:small;"><span style="font-family:Times New Roman,serif;"><span style="color:#000000;"><a class="sdfootnoteanc" name="sdfootnote1anc" href="#sdfootnote1sym"><sup>6</sup></a></span></span></span></span></span></sup><a class="sdfootnotesym" name="sdfootnote1sym" href="#sdfootnote1anc"><br />
</a></p>
<div id="sdfootnote1"><a href="http://kanian77.files.wordpress.com/2008/09/mvc_mixed.jpg"><img class="alignnone size-full wp-image-29" src="http://kanian77.files.wordpress.com/2008/09/mvc_mixed.jpg?w=291&#038;h=138" alt="" width="291" height="138" /></a></div>
<p style="margin-bottom:0;font-style:normal;" lang="fr-FR" align="left"><span style="color:#000000;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">With this solution there are three communication cycles between the different components of the apllication:</span></span></span></p>
<ul>
<li>
<p style="margin-bottom:0;" align="left"><span style="font-style:normal;"><span lang="fr-FR"><span style="font-size:small;"><span style="color:#000000;"><span><span style="font-family:TimesNewRomanPS-ItalicMT,serif;">The 	« User </span><span style="font-family:TimesNewRomanPS-ItalicMT,cursive;">→ </span><span style="font-family:TimesNewRomanPS-ItalicMT,serif;">Controller 	(Client) </span><span style="font-family:TimesNewRomanPS-ItalicMT,cursive;">→ </span><span style="font-family:TimesNewRomanPS-ItalicMT,serif;">View (Client) </span><span style="font-family:TimesNewRomanPS-ItalicMT,cursive;">→</span></span><span style="font-family:TimesNewRomanPS-ItalicMT,serif;">User » 	cycle:</span></span></span></span></span></p>
</li>
</ul>
<p style="margin-left:0.64cm;margin-bottom:0;font-style:normal;" lang="fr-FR" align="left"><span style="color:#000000;"><span style="font-family:TimesNewRomanPS-ItalicMT,serif;"><span style="font-size:small;">In this case the user action is intercepted by the client-side Controller which decides that only the client-side View( the UI) is affected by the User&#8217;s action. The client-side Controller will update the client-side View that will make the modifications visible to the User.</span></span></span></p>
<ul>
<li>
<p style="margin-bottom:0;font-style:normal;" lang="fr-FR" align="left"><span style="color:#000000;"><span style="font-family:TimesNewRomanPS-ItalicMT,serif;"><span style="font-size:small;">The 	« User → Controller (Client) → Controller(Server) 	→View (Server) → View (Client)→User » cycle:</span></span></span></p>
</li>
</ul>
<p style="margin-left:0.64cm;margin-bottom:0;font-style:normal;" lang="fr-FR" align="left"><span style="color:#000000;"><span style="font-family:TimesNewRomanPS-ItalicMT,serif;"><span style="font-size:small;">Here the User action is intercepted by the client-side Controller which decides to send them as HTTP request to the server-side Controller. The server-side Controller will update the server-side View and send it to the client-side View. For example, this communication cycle can be used when a User wants to change  the application presentation (layout). </span></span></span></p>
<ul>
<li>
<p style="margin-bottom:0;font-style:normal;" lang="fr-FR" align="left"><span style="color:#000000;"><span style="font-family:TimesNewRomanPS-ItalicMT,serif;"><span style="font-size:small;">The 	« User → Controller (Client) → Controller(Server) → 	Model → View (Server) → View(Client) → User » 	cycle:</span></span></span></p>
</li>
</ul>
<p style="margin-left:0.64cm;margin-bottom:0;" align="left"><span style="font-style:normal;"><span lang="fr-FR"><span style="font-size:small;"><span style="font-family:TimesNewRomanPS-ItalicMT,serif;"><span style="color:#000000;">Is similar to the precedent. The difference here is that the server-side controller decides that the Model should be updated and updates the server-side View that will be sent to the client-side View and finally displayed to the User.</span></span></span></span></span><sup><span style="font-style:normal;"><span lang="fr-FR"><span style="font-size:small;"><span style="font-family:TimesNewRomanPS-ItalicMT,serif;"><span style="color:#000000;"><a class="sdfootnoteanc" name="sdfootnote1anc" href="#sdfootnote1sym"><sup>7</sup></a></span></span></span></span></span></sup></p>
<p style="margin-bottom:0;" align="left"><strong><span lang="fr-FR"><span style="font-size:small;"><span style="font-family:Times New Roman,serif;"><span style="color:#000000;">Mixed client-side and server-side MVC (2)</span></span></span></span></strong><sup><strong><span lang="fr-FR"><span style="font-size:small;"><span style="font-family:Times New Roman,serif;"><span style="color:#000000;"><a class="sdfootnoteanc" name="sdfootnote1anc" href="#sdfootnote1sym"><sup>8</sup></a></span></span></span></span></strong></sup></p>
<div id="sdfootnote1">
<p class="sdfootnote"><a class="sdfootnotesym" name="sdfootnote1sym" href="#sdfootnote1anc"><br />
</a></p>
</div>
<div id="sdfootnote1">
<p style="margin-bottom:0;"><a href="http://kanian77.files.wordpress.com/2008/09/mvc_mixed2.jpg"><img class="alignnone size-full wp-image-30" src="http://kanian77.files.wordpress.com/2008/09/mvc_mixed2.jpg?w=423&#038;h=112" alt="" width="423" height="112" /></a></p>
<p style="margin-bottom:0;" lang="fr-FR" align="left"><span style="color:#000000;"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">With this approach the client-side Model contains a copy of the data the user wants to access. It is the client-side Model responsability to communicate with the server-side Controller when the server-side Model needs to be updated or accessed.</span></span></span></p>
<p class="sdfootnote"><strong><span lang="fr-FR"><span style="font-size:small;"><span style="font-family:Times New Roman,serif;"><span style="color:#000000;">Mixed client-side and server-side MVC (3)</span></span></span></span></strong></p>
<p class="sdfootnote"><a href="http://kanian77.files.wordpress.com/2008/09/mvc_mixed3.jpg"><img class="alignnone size-full wp-image-31" src="http://kanian77.files.wordpress.com/2008/09/mvc_mixed3.jpg?w=329&#038;h=166" alt="" width="329" height="166" /></a></p>
<p class="sdfootnote">One can imagine and develop web applications where only part the M of the MVC lives on the server. Morales-Chaparo et al call this approach RIA MVC. This allows for part of the less critical operations involving the model to happen at the client. A request is sent to server only when the client-side Model needs access to the server-side Model.</p>
<p class="sdfootnote">&#8212;&#8212;-</p>
<p class="sdfootnote">Note:</p>
<p class="sdfootnote">I believe that more and more web applications developpers will chose this &#8220;almost all client-side web MVC pattern&#8221;. Already, some javascript frameworks are openly claiming adhering to the MVC pattern (<a href="http://www.javascriptMVC.com" target="_blank">javascriptMVC</a>).</p>
<p class="sdfootnote">&#8212;&#8212;-</p>
<p class="sdfootnote" style="margin-left:0;text-indent:0;" lang="fr-FR"><span style="color:#000000;"><span style="font-size:x-small;"><br />
</span></span></p>
</div>
<p class="sdfootnote">
<div id="sdfootnote1">
<p style="margin-bottom:0;" align="left"><em><a class="sdfootnotesym" name="sdfootnote1sym" href="#sdfootnote1anc">1</a><span><span lang="fr-FR"><span style="color:#000000;"><span style="font-size:small;"> </span><span style="font-size:x-small;">ARCHITECTURAL DESIGN OF 	MODERN WEB APPLICATIONS</span><span style="font-size:small;">, </span><span style="font-size:x-small;"><span style="font-family:Times New Roman,serif;">Lech 	MADEYSKI, Michał STOCHMIAŁEK, Wroclaw University of Technology, 	Poland.</span></span></span></span></span></em></p>
<p><a class="sdfootnotesym" name="sdfootnote1sym" href="#sdfootnote1anc"><br />
</a><a class="sdfootnotesym" name="sdfootnote1sym" href="#sdfootnote1anc"> 2</a><span style="color:#000080;"><span style="text-decoration:underline;"><a href="http://osteele.com/archives/2004/08/web-mvc"> Web MVC, http://osteele.com/archives/2004/08/web-mvc</a></span></span> ,Oliver Steele, 2004</div>
<div id="sdfootnote1">
<p class="sdfootnote" style="margin-left:0;text-indent:0;" lang="fr-FR"><a class="sdfootnotesym" name="sdfootnote1sym" href="#sdfootnote1anc">3</a><span lang="fr-FR"><span style="font-size:x-small;"><span style="color:#000000;"> Understanding JavaServer Pages Model 2 architecture, Exploring the 	MVC design pattern, Govind Seshadri,</span></span></span><span style="color:#000000;"><span style="font-size:x-small;"> JavaWorld.com, 12/29/99</span></span></p>
<div id="sdfootnote1">
<p class="sdfootnote"><a class="sdfootnotesym" name="sdfootnote1sym" href="#sdfootnote1anc">4</a> Apache 	Struts, <span style="color:#000080;"><span style="text-decoration:underline;"><a href="http://struts.apache.org/">http://struts.apache.org/</a></span></span>, 	 is a  framework for creating enterprise-ready Java web applications</p>
</div>
<div id="sdfootnote2">
<p class="sdfootnote"><a class="sdfootnotesym" name="sdfootnote2sym" href="#sdfootnote2anc">5 </a>http://struts.apache.org/primer.html#mvc</p>
</div>
<div id="sdfootnote2"><a class="sdfootnotesym" name="sdfootnote1sym" href="#sdfootnote1anc">6</a><span lang="fr-FR"><span style="font-size:x-small;"><span style="color:#000000;">MVC Web design patterns and Rich Internet Applications, Morales-Chaparro, R.; Linaje, M.; Preciado, J. C.; Sánchez-Figueroa F.</span></span></span><span style="color:#000000;"><span style="font-size:x-small;"> QUERCUS Software Engineering Group, Escuela Politécnica. Universidad de Extremadura</span></span></div>
<p style="margin-bottom:0;"><a class="sdfootnotesym" name="sdfootnote1sym" href="#sdfootnote1anc">7</a><span style="font-size:x-small;"> ibid</span></p>
<p><a class="sdfootnotesym" name="sdfootnote1sym" href="#sdfootnote1anc">8 </a>ibid</div>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/kanian77.wordpress.com/25/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/kanian77.wordpress.com/25/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kanian77.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kanian77.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kanian77.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kanian77.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kanian77.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kanian77.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kanian77.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kanian77.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kanian77.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kanian77.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kanian77.wordpress.com&blog=2054282&post=25&subd=kanian77&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kanian77.wordpress.com/2008/09/04/vi-mvc-and-the-web/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1cea03b59b7d4d488bd796e423551e8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kanian77</media:title>
		</media:content>

		<media:content url="http://kanian77.files.wordpress.com/2008/09/mvc.jpg" medium="image" />

		<media:content url="http://kanian77.files.wordpress.com/2008/09/mvc_model21.jpg" medium="image" />

		<media:content url="http://kanian77.files.wordpress.com/2008/09/mvc_mixed.jpg" medium="image" />

		<media:content url="http://kanian77.files.wordpress.com/2008/09/mvc_mixed2.jpg" medium="image" />

		<media:content url="http://kanian77.files.wordpress.com/2008/09/mvc_mixed3.jpg" medium="image" />
	</item>
		<item>
		<title>The Benefits and Drawbacks of using The MVC Pattern</title>
		<link>http://kanian77.wordpress.com/2008/09/03/the-benefits-and-drawbacks-of-using-the-mvc-pattern/</link>
		<comments>http://kanian77.wordpress.com/2008/09/03/the-benefits-and-drawbacks-of-using-the-mvc-pattern/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 23:54:27 +0000</pubDate>
		<dc:creator>kanian77</dc:creator>
				<category><![CDATA[MVC and the web]]></category>

		<guid isPermaLink="false">http://kanian77.wordpress.com/?p=22</guid>
		<description><![CDATA[The Benefits of using The MVC Pattern<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kanian77.wordpress.com&blog=2054282&post=22&subd=kanian77&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="margin-bottom:0;" align="left"><strong><span style="font-size:small;"><span style="font-family:TimesNewRoman,serif;">IV The Benefits of using The MVC Pattern</span></span></strong><sup><strong><span style="font-size:small;"><span style="font-family:TimesNewRoman,serif;"><a class="sdfootnoteanc" name="sdfootnote1anc" href="#sdfootnote1sym"><sup>1</sup></a></span></span></strong></sup></p>
<ul>
<li> Different views and controllers can be substituted to provide alternate user interfaces for the same model.</li>
<li> Multiple simultaneous views of the same model</li>
<li> The change propagation mechanism insures that all views simultaneously reflect the current state of the model.</li>
<li>Changes affecting just the user interface of the application  become easier to make.</li>
<li> With MVC it can be easier to test the core of the application, as encapsulated by the model.</li>
</ul>
<p style="margin-bottom:0;" align="left"><strong><span style="font-size:small;"><span style="font-family:TimesNewRoman,serif;">V The problems of MVC</span></span></strong><sup><strong><span style="font-style:normal;"><span style="font-size:small;"><span style="font-family:TimesNewRoman,serif;"><a class="sdfootnoteanc" name="sdfootnote2anc" href="#sdfootnote2sym"><sup>2</sup></a></span></span></span></strong></sup></p>
<ul>
<li>There&#8217;s increased complexity as an apllication may use other 	patterns at the same time as MVC.</li>
<li>The view and the controller are closely coupled wich makes 	modification to one affect the other.</li>
<li>Changes to the model interface will necessitate changes to 	the controller and the view.</li>
<li>When the model is active frequent changes to model can result 	in excessive updates of the corresponding views.</li>
</ul>
<div id="sdfootnote1">
<p class="sdfootnote"><a class="sdfootnotesym" name="sdfootnote1sym" href="#sdfootnote1anc">1 </a></p>
<p style="margin-bottom:0;" align="left"><span><span style="font-size:x-small;"><span style="font-family:TimesNewRoman,serif;">Model View Controller explication page of the phpWACT framework, http://www.phpwact.org/pattern/model_view_controller</span></span></span></p>
<p class="sdfootnote"><span style="font-size:x-small;"></span></p>
</div>
<div id="sdfootnote2">
<p style="margin-bottom:0;" align="left"><a class="sdfootnotesym" name="sdfootnote2sym" href="#sdfootnote2anc">2</a><span><span style="font-size:x-small;"><span style="font-family:TimesNewRoman,serif;">ibid</span></span></span></p>
</div>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/kanian77.wordpress.com/22/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/kanian77.wordpress.com/22/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kanian77.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kanian77.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kanian77.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kanian77.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kanian77.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kanian77.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kanian77.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kanian77.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kanian77.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kanian77.wordpress.com/22/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kanian77.wordpress.com&blog=2054282&post=22&subd=kanian77&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kanian77.wordpress.com/2008/09/03/the-benefits-and-drawbacks-of-using-the-mvc-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1cea03b59b7d4d488bd796e423551e8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kanian77</media:title>
		</media:content>
	</item>
		<item>
		<title>How does MVC work?</title>
		<link>http://kanian77.wordpress.com/2008/09/03/iii-how-does-mvc-work/</link>
		<comments>http://kanian77.wordpress.com/2008/09/03/iii-how-does-mvc-work/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 23:42:52 +0000</pubDate>
		<dc:creator>kanian77</dc:creator>
				<category><![CDATA[MVC and the web]]></category>

		<guid isPermaLink="false">http://kanian77.wordpress.com/?p=20</guid>
		<description><![CDATA[When the user interacts with an application designed using the MVC principles, the Model, the View, and the Controller communicate together to give the user the ability to interact with the Model and perceive the expected results.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kanian77.wordpress.com&blog=2054282&post=20&subd=kanian77&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="margin-bottom:0;font-style:normal;" align="left"><span style="font-family:TimesNewRoman,Italic,serif;"><span style="font-size:small;"><strong><br />
</strong></span></span></p>
<p style="margin-bottom:0;font-style:normal;" align="left"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">When the user interacts with an application designed using the MVC principles,  the Model, the View, and the Controller communicate together  to give the user the ability to interact with the Model and perceive the expected results.</span></span></p>
<p style="margin-bottom:0;font-style:normal;" align="left"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">There are many ways in which the Model, the View and the Controller can work together as explained by  Trygve Reenskaug in his paper.</span></span></p>
<p style="margin-bottom:0;font-style:normal;" align="left">
<p style="margin-bottom:0;font-style:normal;" align="left"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>III.1 The passive model </strong></span></span></p>
<p style="margin-bottom:0;font-style:normal;" align="left"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Here the Model reacts only to the Controller&#8217;s requests and View&#8217;s requests (if any). That is the Model would modify or retrieve data it represents only on the initiative of the Controller or the View. So upon the user&#8217;s request the controller would transmit the command to the Model and notify the View of a change in the Model&#8217;s state. The View could then request the changes to the Model or the Controller could trasmit those changes to the View. The Model is thus passive.</span></span></p>
<p style="margin-bottom:0;font-style:normal;" align="left">
<p style="margin-bottom:0;font-style:normal;" align="left"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>III.2 The active model </strong></span></span></p>
<p style="margin-bottom:0;font-style:normal;" align="left"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">If  the data represented by the Model can change as a result of actions from objects other than its View or Controller, then there must be a way for the Model to notify its View of the change. A communication channel must exist between the Model and its View.  In such case, the Model must initiate communication with the View. The Model is said to be active.</span></span></p>
<p style="margin-bottom:0;font-style:normal;" align="left">
<p style="margin-bottom:0;font-style:normal;" align="left"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><strong>III.3 The communication between the View and the Controller</strong></span></span></p>
<p style="margin-bottom:0;" align="left"><span style="font-style:normal;"><span style="font-size:small;"><span style="font-family:Times New Roman,serif;">As explained in </span></span><span lang="en-ZA"><span style="font-size:small;"><span style="font-family:TimesNewRoman,serif;">Steve Burbeck 1992 paper on MVC and Smalltalk:</span></span></span></span></p>
<p style="margin-bottom:0;" align="left"><span style="font-size:small;"><span style="font-family:Times New Roman,serif;"><em><span>Each view is associated with a unique controller and vice versa.  Instance variables in each 	maintain this tight coupling.  A view&#8217;s instance variable <strong>controller</strong> points at its controller, 	and a controller&#8217;s instance variable <strong>view</strong> points at its associated view.  And, because both 	must communicate with their model, each has an instance 	variable model which points to the 	model object.  So, although the model is limited to sending self changed:,  both 	the view and 	the controller can send messages directly to each other and to their model.</span></em></span></span></p>
<p style="margin-bottom:0;" align="left"><span style="font-size:small;"><span style="font-family:TimesNewRoman,serif;">In this excerpt <em>&#8217;self changed&#8217;</em> is the message that the active model sends to its views to tell them that its state has been modified.</span></span></p>
<p style="margin-bottom:0;" align="left">
<p style="margin-bottom:0;" align="left"><span style="font-family:TimesNewRoman,serif;"><span style="font-size:small;">&#8212;&#8212;&#8212;-</span></span></p>
<p style="margin-bottom:0;" align="left"><span style="font-family:TimesNewRoman,serif;"><span style="font-size:small;"><strong>Note:</strong></span></span></p>
<p style="margin-bottom:0;" align="left"><span style="font-family:TimesNewRoman,serif;"><span style="font-size:small;">The tight coupling of the view and the controller have pushed some implementers of the MVC pattern in the GUI world to combine the view and the controller into one element called the View, whereas the model is called the Document. Such a pattern is then called the Document View pattern</span></span><sup><a class="sdfootnoteanc" name="sdfootnote1anc" href="#sdfootnote1sym"><sup>1</sup></a></sup><span style="font-size:small;"><span style="font-family:TimesNewRoman,serif;"> </span></span></p>
<p style="margin-bottom:0;" align="left"><span style="font-family:TimesNewRoman,serif;"><span style="font-size:small;">&#8212;&#8212;&#8212;&#8211; </span></span></p>
<p style="margin-bottom:0;" align="left">
<div id="sdfootnote1">
<p style="margin-bottom:0;" align="left"><a class="sdfootnotesym" name="sdfootnote1sym" href="#sdfootnote1anc">1</a><span><span style="font-size:x-small;"><span style="font-family:TimesNewRoman,serif;"> Model View Controller explication page of the phpWACT framework, 	http://www.phpwact.org/pattern/model_view_controller</span></span></span></p>
</div>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/kanian77.wordpress.com/20/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/kanian77.wordpress.com/20/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kanian77.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kanian77.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kanian77.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kanian77.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kanian77.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kanian77.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kanian77.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kanian77.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kanian77.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kanian77.wordpress.com/20/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kanian77.wordpress.com&blog=2054282&post=20&subd=kanian77&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kanian77.wordpress.com/2008/09/03/iii-how-does-mvc-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1cea03b59b7d4d488bd796e423551e8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kanian77</media:title>
		</media:content>
	</item>
		<item>
		<title>MVC and Object Orientation</title>
		<link>http://kanian77.wordpress.com/2008/09/03/16/</link>
		<comments>http://kanian77.wordpress.com/2008/09/03/16/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 23:34:38 +0000</pubDate>
		<dc:creator>kanian77</dc:creator>
				<category><![CDATA[MVC and the web]]></category>

		<guid isPermaLink="false">http://kanian77.wordpress.com/?p=16</guid>
		<description><![CDATA[From what we read so far we understand that MVC separates the presentation of data, the handling of data, and the intepretation of user actions into different layers.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kanian77.wordpress.com&blog=2054282&post=16&subd=kanian77&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="margin-bottom:0;font-style:normal;" align="left"><span style="font-family:TimesNewRoman,Italic,serif;"><span style="font-size:small;"><strong>II. MVC and Object Orientation</strong></span></span></p>
<p style="margin-bottom:0;" align="left"><span style="font-style:normal;"><span style="font-size:small;"><span style="font-family:TimesNewRoman,serif;">From <a href="http://kanian77.wordpress.com/2008/09/03/very-brief-history-of-mvc/" target="_blank">what we read so far</a> we understand that MVC separates the presentation of data, the handling of data, and the intepretation of user actions into different layers. One of the stated benefits by </span></span><span style="font-size:small;"><span style="font-family:Times New Roman,serif;">Trygve Reenskaug is the fact that data could be presented from mutiple perspectives. This means that, since the presentation (View) and the description of the data (Model) are embodied into different loosely coupled  layers or components,  the same data can be presented to the user in many different ways. That is, the data is not tied to the way it is being shown to the user. Moreover, let&#8217;s read this excerpt from </span></span><span lang="en-ZA"><span style="font-size:small;"><span style="font-family:TimesNewRoman,serif;"><a href="http://www.google.co.za/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fst-www.cs.uiuc.edu%2Fusers%2Fsmarch%2Fst-docs%2Fmvc.html&amp;ei=mBq_SLDlLoWgQITkoSk&amp;usg=AFQjCNGp2Y00vYssncqCh0OFSx4pyeUdHQ&amp;sig2=ai6Qb9HkzESAM7mFLvsX7Q" target="_blank">Steve Burbeck&#8217;s text</a>:</span></span></span><span style="font-size:small;"><span style="font-family:Times New Roman,serif;"> </span></span></span></p>
<p style="margin-bottom:0;" align="left"><span><span style="font-size:small;"><span style="font-family:Times New Roman,serif;"><span style="font-style:normal;"> </span><em>The formal separation of these three tasks is an important notion that is particularly suited to 	Smalltalk-80 where the basic behavior can be embodied in abstract objects: View, Controller, 	Model and Object.  The MVC behavior is then inherited, added to, and modified as necessary to 	provide a flexible and powerful system.</em></span></span></span></p>
<p style="margin-bottom:0;font-style:normal;" align="left"><span style="font-family:TimesNewRoman,Italic,serif;"><span style="font-size:small;">We see how MVC is well suited to be implemented using object oriented techniques. As a matter of facts, Trygve Reenskaugh in his Models-Views-controllers note writes on models:</span></span></p>
<p style="margin-bottom:0;" align="left"><span style="font-size:small;"><span style="font-family:Times New Roman,serif;"><span style="font-style:normal;"> </span><em>The models are represented in the computer as a collection of data together with the methods</em></span></span></p>
<p style="margin-bottom:0;" align="left"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;"><em> necessary to process these data.</em></span></span></p>
<p style="margin-bottom:0;font-style:normal;" align="left"><span style="font-family:Times New Roman,serif;"><span style="font-size:small;">Now if this is not the description of an object, then what is it? Now if  models can be  understood as objects in MVC, why not think of Views and Controller as other classes of objects? The fact is that a lot of systems using the MVC pattern also use the object oriented pattern. How well do both patterns fit together and how to better use them together? These are the questions that the developper of such systems and frameworks have probably tried to answer. Let us just remember that both patterns have been applied  successfully in Smalltalk-80, with the object orientation supporting the MVC pattern. </span></span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/kanian77.wordpress.com/16/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/kanian77.wordpress.com/16/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kanian77.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kanian77.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kanian77.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kanian77.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kanian77.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kanian77.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kanian77.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kanian77.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kanian77.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kanian77.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kanian77.wordpress.com&blog=2054282&post=16&subd=kanian77&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kanian77.wordpress.com/2008/09/03/16/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1cea03b59b7d4d488bd796e423551e8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kanian77</media:title>
		</media:content>
	</item>
		<item>
		<title>Very Brief History Of MVC</title>
		<link>http://kanian77.wordpress.com/2008/09/03/very-brief-history-of-mvc/</link>
		<comments>http://kanian77.wordpress.com/2008/09/03/very-brief-history-of-mvc/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 23:25:59 +0000</pubDate>
		<dc:creator>kanian77</dc:creator>
				<category><![CDATA[MVC and the web]]></category>
		<category><![CDATA[javascript and mvc]]></category>

		<guid isPermaLink="false">http://kanian77.wordpress.com/?p=13</guid>
		<description><![CDATA[In a paper published by Trygve Reenskaug in 2007, he explained when and why was the MVC pattern created.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kanian77.wordpress.com&blog=2054282&post=13&subd=kanian77&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I. Very Brief History Of MVC</p>
<p>In a<a href="http://www.google.co.za/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Ffolk.uio.no%2Ftrygver%2F2007%2FMVC_Originals.pdf&amp;ei=whm_SPjsHIPO0gWm6pBv&amp;usg=AFQjCNGUju-NmoG6JwYpEkFYtJtxagmj-g&amp;sig2=c1uh76IQ5N3EafMqbsSKrA" target="_blank"> paper</a> published by Trygve Reenskaug in 2007, he explained when and why was the MVC pattern created. Here is what he said:</p>
<p align="justify"><em>&#8220;I made the first implementation and wrote the original MVC reports while I</p>
<p>was a visiting scientist at Xerox Palo Alto Research Laboratory (PARC) in</p>
<p>1978/79. MVC was created as an obvious solution to the general problem of</p>
<p>giving users control over their information as seen from multiple perspectives.</p>
<p>MVC has created a surprising amount of interest.&#8221;</em></p>
<p>It is important to note that the pattern in it first days did not carry the name of MVC, but rather the lengthy name of THING-MODEL-VIEW-EDITOR as it was described in a note entitled « THING-MODEL-VIEW-EDITOR -.an <a href="http://www.google.co.za/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Ffolk.uio.no%2Ftrygver%2F1979%2Fmvc-1%2F1979-05-MVC.pdf&amp;ei=uxy_SKbBOZ3wQezinC4&amp;usg=AFQjCNFi6C7IZs_aY8eVH_UV8L2_QEy8Yw&amp;sig2=ipqC8-V4V0GXoe9bi_Sv4A">Example from a planningsystem</a> » published in May 1979.</p>
<p>However, just a few month later, in December 1979, the terms Model,View, and Controller were adopted by Reenskaug in the MODELS &#8211; VIEWS – CONTROLLERS note. In this note Trygve Reenskaug discuss the meaning of the M, V and C of MVC. He describes the Model by these words:</p>
<p align="justify"><em>&#8220; Models represent knowledge. A model could be a single object (rather uninteresting), or it</p>
<p>could be some structure of objects. &#8221;</em></p>
<p>He explains that:</p>
<p align="justify"><em>&#8220;A view is a (visual) representation of its model. It would ordinarily highlight certain attributes</p>
<p>of the model and suppress others. It is thus acting as a presentation filter.&#8221;</em></p>
<p>Finally he states that:</p>
<p align="justify"><em>&#8220;A controller is the link between a user and the system. (&#8230;)</p>
<p>The controller receives such user output, translates it into the appropriate</p>
<p>messages and pass these messages on to one or more of the views.&#8221;</em></p>
<p>After Trygve Reenskaug left Xerox PARC, Jim Althoff and others implemented a version of MVC for the Smalltalk-80 class library, whose first public release happened in 1983. If fact in their « The Language and its Implementation », a book on Smalltalk-80, Aele Goldberg (who had discussed the renaming of THING-MODEL-VIEW-EDITOR to Model-View-Controller with Reenskaug ) and David Robson present MVC and its use in Smalltalk.</p>
<p>A <a href="http://www.google.co.za/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Fst-www.cs.uiuc.edu%2Fusers%2Fsmarch%2Fst-docs%2Fmvc.html&amp;ei=mBq_SLDlLoWgQITkoSk&amp;usg=AFQjCNGp2Y00vYssncqCh0OFSx4pyeUdHQ&amp;sig2=ai6Qb9HkzESAM7mFLvsX7Q" target="_blank">description</a> of the MVC pattern as implemented in Smalltalk-80 v2.5 written by Steve Burbeck in 1992 (a 1987 version exists) presents it with these words:</p>
<p align="justify"><em>&#8220;In the MVC paradigm the user input, the modeling of the external world, and the visual feedback to the user are explicitly separated and handled by three types of object, each specialized for its task. The view manages the graphical and/or textual output to the portion of the bitmapped display that is allocated to its application. The controller interprets the mouse and keyboard inputs from the user, commanding the model and/or the view to change as appropriate. Finally, the model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller).&#8221; </em></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/kanian77.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/kanian77.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kanian77.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kanian77.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kanian77.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kanian77.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kanian77.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kanian77.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kanian77.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kanian77.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kanian77.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kanian77.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kanian77.wordpress.com&blog=2054282&post=13&subd=kanian77&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kanian77.wordpress.com/2008/09/03/very-brief-history-of-mvc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1cea03b59b7d4d488bd796e423551e8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kanian77</media:title>
		</media:content>
	</item>
		<item>
		<title>Using ZEND_Config Part 2</title>
		<link>http://kanian77.wordpress.com/2007/11/06/using-config-part-2/</link>
		<comments>http://kanian77.wordpress.com/2007/11/06/using-config-part-2/#comments</comments>
		<pubDate>Tue, 06 Nov 2007 09:52:21 +0000</pubDate>
		<dc:creator>kanian77</dc:creator>
				<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://kanian77.wordpress.com/2007/11/06/using-config-part-2/</guid>
		<description><![CDATA[ Last Time
At the end of the last discussion on Zend_Config, I mentioned how it would be interesting to leverage the code already existing in Zend_Confing, instead of reinventing the wheel. Our main issue was how to use defined PHP constants in an ini file (or in an xml   file).
View a better formatted [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kanian77.wordpress.com&blog=2054282&post=11&subd=kanian77&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h2><font color="#000000"> Last Time</font></h2>
<p><font color="#000000">At the end of the last discussion on Zend_Config, I mentioned how it would be interesting to leverage the code already existing in Zend_Confing, instead of reinventing the wheel. Our main issue was how to use defined PHP constants in an ini file (or in an xml   file).</font></p>
<p><font color="#000000"><a href="http://kanian77.pastebin.com/f7973c04e">View a better formatted version of the code in this post here </a></font></p>
<h2><font color="#000000"> A Solution</font></h2>
<p><font color="#000000">We will extend Zend_Config_Ini with a custom method to find references to defined constants in a configuration object and resolve them. The resulting class should function exactly as Zend_Config_Ini would for &#8220;normal&#8221; ini files. First we need to know what are the constants already defined at the time Zend_Config_Ini parses our ini file. PHP  does this easily<br />
with the get_defined_constants() function (available in PHP 4 &gt;= 4.1.0, PHP 5). Next we need to tell our extending class when it can find and replace defined PHP constants in a configuration object.</font></p>
<h2><font color="#000000"> Extending Zend_Config_Ini</font></h2>
<p><font color="#000000">We will call our new class </font><font color="#000000">ConfigPhp (I&#8217;m sure you could find a better name):</font></p>
<blockquote><p><font color="#000000"><code>class ConfigPhp extends Zend_Config_Ini{ //...}</code></font></p></blockquote>
<p><font color="#000000">Its constructor shall refer to  </font><font color="#000000">Zend_Config_Ini constructor.</font></p>
<h2><font color="#000000"> Tell ConfigPhp When To Parse Defined Constants</font></h2>
<p><font color="#000000">We need to tell ConfigPHP when our ini file contains PHP defined constants. </font><font color="#000000">The ConfigPhp constructor can be used:</font></p>
<blockquote><p><font color="#000000"><code>public function __construct($filename, $section, $config = false)</code><br />
</font> <font color="#000000"><code> {</code><br />
</font> <font color="#000000"><code> if (is_array($config))</code><br />
</font> <font color="#000000"><code> {</code><br />
</font> <font color="#000000"><code> $this-&gt;php_defs = $config["php_defs"];</code><br />
</font> <font color="#000000"><code> $this-&gt;allow_mods = $config["allow_mods"];</code><br />
</font> <font color="#000000"><code> } //...</code><br />
</font> <font color="#000000"><code> }</code></font><font color="#000000"><code></code></font></p></blockquote>
<p><font color="#000000">Where <code>$config["php_defs"]</code> is a boolean telling whether or not the ini file contains defined PHP constants.</font></p>
<h2><font color="#000000"> Using Defined PHP Constants</font></h2>
<p><font color="#000000">When our ini file contains defined PHP constants, and we have told ConfigPhp </font><font color="#000000">by setting $config["php_defs"] to true, the constants are found in the configuration object and replaced with their real values.</font></p>
<blockquote><p><font color="#000000"><code>if($this-&gt;php_defs)</code><br />
</font> <font color="#000000"><code> {</code><br />
</font> <font color="#000000"><code> $this-&gt;data = $this-&gt;toArray();</code><br />
</font> <font color="#000000"><code> $this-&gt;parsePHPDefs();</code><br />
</font> <font color="#000000"><code> }</code></font></p></blockquote>
<h2><font color="#000000"> The parsePHPDefs() method</font></h2>
<p><font color="#000000">The parsePHPDefs() is the </font><font color="#000000">heart of this extension. It will </font><font color="#000000">retrieve the data contained in the Zend_Config_Ini object and for </font><font color="#000000">all ocurences of defined PHP constants replaces them with their real value:</font></p>
<blockquote><p><font color="#000000"><code>protected function parsePHPDefs()</code><br />
</font> <font color="#000000"> <code>{</code><br />
</font> <font color="#000000"><code> $report_error = null;</code><br />
</font> <font color="#000000"><code> $this-&gt;defined_constants = get_defined_constants(true);</code><br />
</font> <font color="#000000"><code> if (is_array($this-&gt;defined_constants["user"]))</code><br />
</font> <font color="#000000"><code> {</code><br />
</font> <font color="#000000"><code> foreach($this-&gt;defined_constants["user"] as $key =&gt; $value)</code><br />
</font> <font color="#000000"><code> {</code><br />
</font> <font color="#000000"><code> foreach($this-&gt;data as $datakey =&gt; $dataval)</code><br />
</font> <font color="#000000"><code> {       </code><code></code><br />
</font> <font color="#000000"><code> if($datakey == 'includes')</code><br />
</font> <font color="#000000"><code> {</code><br />
</font> <font color="#000000"><code> $report_error = ini_get('error_reporting');</code><br />
</font> <font color="#000000"><code> error_reporting(0);</code><br />
</font> <font color="#000000"><code> foreach($dataval as $inckey =&gt; $incval)</code><br />
</font> <font color="#000000"><code> {</code><br />
</font> <font color="#000000"><code> $pattern = '/(\.)?'.$key.'(\.)?/';</code><br />
</font> <font color="#000000"><code> $incval = preg_replace($pattern , $value, $incval);</code><br />
</font> <font color="#000000"><code>  error_reporting($report_error);</code><br />
</font> <font color="#000000"><code> $this-&gt;data["includes"][$inckey] = $incval;</code><br />
</font> <font color="#000000"><code> $this-&gt;__set($inckey,$incval);</code><br />
</font> <font color="#000000"><code> }</code><br />
</font> <font color="#000000"><code> }</code><br />
</font> <font color="#000000"> <code></code><br />
<code> }</code><br />
<code> }</code><br />
<code> }</code><br />
<code> }</code><br />
<code></code></font></p></blockquote>
<p><font color="#000000"><code> </code><br />
The </font><font color="#000000"><code>get_defined_constants(true)</code> method will return an array of arrays. Each key in that array refers to the origin of the defined constants in the array it has as value. Thus<br />
<code>$this-&gt;defined_constants = get_defined_constants(true);<br />
$this-&gt;defined_constants["user"]</code> will refer to the constants we have defined (at a point or another before this code is reached). For each defined constant we search each value in our </font> <font color="#000000">Zend_Config_Ini object and for each occurence of it replace it with the actual value of the constant. You would notice the line </font><font color="#000000"><code>if($datakey == 'includes')</code>. It just that  the values I have in my ini file all start by the string &#8220;includes.&#8221;. It would be easy to parameterized this, and be able to replace arbitrary values in the ini file. In fact I use the Zend_Config_Ini object to set my include_path. I created a method to do so:</font></p>
<blockquote><p><font color="#000000"><code>function makeIncludePath()</code><br />
</font> <font color="#000000"><code> {</code><br />
</font> <font color="#000000"><code> foreach($this-&gt;data as $datakey =&gt; $dataval)</code><br />
</font> <font color="#000000"><code> {	</code><br />
</font> <font color="#000000"> <code></code><br />
</font> <font color="#000000"><code> if($datakey == 'includes')</code><br />
</font> <font color="#000000"><code> {</code><br />
</font> <font color="#000000"> <code></code><br />
</font> <font color="#000000"><code> foreach($dataval as $inckey =&gt; $incval)</code><br />
</font> <font color="#000000"><code> {</code><br />
</font> <font color="#000000"><code> $this-&gt;include_path.=$incval. DS.PATH_SEPARATOR;</code><br />
</font> <font color="#000000"><code> }</code><br />
</font> <font color="#000000"><code> }</code><br />
</font> <font color="#000000"> <code></code><br />
</font> <font color="#000000"><code> }//....}</code></font></p></blockquote>
<h2><font color="#000000"> Advantages</font></h2>
<p><font color="#000000">Let&#8217;s say you are </font><font color="#000000">integrating a third party library to Zend and would like to make some </font><font color="#000000">constants defined in the library available to your Zend Application, but you </font><font color="#000000">want to use Zend_Config_Ini and &#8230; an ini file. This approach would allow you to access the third party library (or application) defined constants within your ini file.</font></p>
<h2><font color="#000000"> Rationale</font></h2>
<p><font color="#000000">The approach itself </font><font color="#000000">might seem a bit of an overkill. I mean </font><font color="#000000">why use predefined constants in an ini? The point here is that it is possible, and someone out there might need such a feature. I do for once. </font><font color="#000000">I would use Zend_Config to help me in setting paths (Include_path) during the bootstrap process. To bootstrap, </font><font color="#000000">I need to define a minimal set of PHP constants. For example:</font></p>
<blockquote><p><font color="#000000"><code>//Forced to have these declarations here as a minimum requirement for bootstrap to happen<br />
if(!defined('DS'))<br />
{<br />
define('DS',DIRECTORY_SEPARATOR);<br />
}<br />
define ('MY_LIBS', dirname(dirname(dirname(__FILE__))).DS.'libs');<br />
define ('MY_APP',dirname(dirname(dirname(__FILE__))).DS.'apps'.DS.'my_app'.DS.'application');<br />
define('MY_ZEND_CORE',dirname(dirname(dirname(__FILE__))).DS.'libs'.DS.'zend'.DS.'library');<br />
if (function_exists('ini_set')) {<br />
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . MY_ZEND_CORE .DS . PATH_SEPARATOR . MY_APP . DS);</code></font></p>
<p><font color="#000000">}<br />
//end bootrap declarations</font></p></blockquote>
<p><font color="#000000">I keep my applications folders and library folders out of the server&#8217;s webroot. So </font><font color="#000000">these constants are needed so I don&#8217;t have to write long paths every time I refer to a file in my app or in the libraries. The </font><font color="#000000">settings in the ini file might need to &#8220;knnow&#8221; about these constants.</font></p>
<h2><font color="#000000"> Improvement</font></h2>
<p><font color="#000000">I am aware that there is room for improvement. The </font><font color="#000000">Zend_Config class itself could be </font><font color="#000000">extended instead of the Zend_Config_Ini class, so that Zend_Config_XML benefits from the parsePHPDefs method. I will probably take more time to see what can be improved. Don&#8217;t hesitate to give your point of view on the matter. You might not even like this approach,  please let me know why.</font></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/kanian77.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/kanian77.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kanian77.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kanian77.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kanian77.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kanian77.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kanian77.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kanian77.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kanian77.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kanian77.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kanian77.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kanian77.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kanian77.wordpress.com&blog=2054282&post=11&subd=kanian77&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kanian77.wordpress.com/2007/11/06/using-config-part-2/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1cea03b59b7d4d488bd796e423551e8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kanian77</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Zend_Config</title>
		<link>http://kanian77.wordpress.com/2007/11/05/configuring-zend/</link>
		<comments>http://kanian77.wordpress.com/2007/11/05/configuring-zend/#comments</comments>
		<pubDate>Mon, 05 Nov 2007 19:57:05 +0000</pubDate>
		<dc:creator>kanian77</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Zend_Config]]></category>

		<guid isPermaLink="false">http://kanian77.wordpress.com/2007/11/05/configuring-zend/</guid>
		<description><![CDATA[There is a Zend Framework class to help in configuring your application. You can use it to save and retrieve configuration data. It&#8217;s called Zend_Config . For examples on how to use  it see http://framework.zend.com/manual/en/zend.config.html.
It allows you to use an &#8216;.ini&#8217; or an xml file to load your configuration settings. You can then access [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kanian77.wordpress.com&blog=2054282&post=5&subd=kanian77&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><font color="#000000">There is a Zend Framework class to help in </font><font color="#000000">configuring your application. You can use it to save and retrieve configuration data. It&#8217;s called </font><font color="#000000">Zend_Config . For examples on how to use  it see </font><font color="#000000">http://framework.zend.com/manual/en/zend.config.html.</font></p>
<p><font color="#000000">It allows you to use an &#8216;.ini&#8217; or an xml file to load your configuration settings. You can then access them as you would of any objects property. Thus if you have this line</font></p>
<blockquote><p><font color="#000000"><code> include.path = 'a/path/'</code></font></p></blockquote>
<p><font color="#000000">in your ini file, after using Zend_Config_Ini, you would access it in this manner</font></p>
<blockquote><p><font color="#000000"><code> $path = $config-&gt;include-&gt;path; </code></font></p></blockquote>
<p><font color="#000000">The process would be similar if you had used xml instead and Zend_Config_Xml.<br />
While being really handy, this method still presents some challenges. An example seaks louder thhan words:</font></p>
<blockquote><p><font color="#000000"><code>includes.APP_MODELS_DIR     = MY_APP.DS.'models';</code></font></p></blockquote>
<p><font color="#000000">where MY_APP and DS are constants defined in my boostrap file, let&#8217;s say.<br />
The </font><font color="#000000">parse_ini_file() php function, used by Zend_Config_Ini does&#8217;nt resolve MY_APP and DS to their proper values. And don&#8217;t even try to use such a syntax</font></p>
<blockquote><p><font color="#000000"><code>includes.APP_MODELS_DIR = &lt;?php MODEL_DIR.DIRECTORY_SEPARATOR."somestring";?&gt;</code></font></p></blockquote>
<p><font color="#000000">otherwise you would get an error. I mean it&#8217;s quite understandable. The </font><font color="#000000">parse_ini_file() function is expecting ini syntax and nothing else.<br />
Since I use constants extensively when defining my paths (app,libs,controllers,vendors paths for example), I &#8216;ld rather create an &#8216;include&#8217; object. For example I would have an &#8216;include.php&#8217; file:</font></p>
<blockquote><p><font color="#000000"><code>$includes = null;</code><br />
</font> <font color="#000000"><code> $includes-&gt;MODELS_DIR = MY_APP.DS.'models';</code><br />
</font> <font color="#000000"><code> $includes-&gt;APP_MODELS_DIR     = MY_APP.DS.'models';</code><br />
</font> <font color="#000000"><code> $includes-&gt;APP_CLASSES_DIR     = MY_APP.DS.'classes';</code><br />
</font> <font color="#000000"><code> $includes-&gt;PLUGINS_DIR     = MY_LIBS.DS.'ZendPlugins';</code><br />
</font> <font color="#000000"><code> $includes-&gt;VIEW_PATH = MY_APP.DS.'views'.DS.'scripts';</code></font></p></blockquote>
<p><font color="#000000">where I can </font><font color="#000000">use previously defined constants (they are defined in the bootstrap file as a necessity for the bootstrap to happen at all).<br />
Then I write a utility function to </font><font color="#000000">parse the object into an &#8216;include string&#8217; that I append to my include path:<br />
<code><code><br />
</code></code></font></p>
<blockquote><p><font color="#000000"><code><code> function makeIncludePath($includes)</code></code><br />
<code><code> {</code></code><br />
<code><code> $include_path='';</code></code><br />
<code><code> if($includes)</code></code><br />
<code><code> {</code></code><br />
<code><code> foreach($includes as $inc)</code></code><br />
<code><code> {$include_path.=$inc. DS.PATH_SEPARATOR;</code>}</code><br />
<code> }</code><br />
<code> ini_set('include_path', ini_get('include_path') . DS.PATH_SEPARATOR.$include_path);</code><br />
<code> }</code><br />
<code></code></font></p></blockquote>
<p><font color="#000000"><code> </code><br />
In a suitable place, before the dispatch process has started, I write<br />
<code><br />
</code></font></p>
<blockquote><p><font color="#000000"><code> require_once 'config_utils.php';</code><br />
<code> require_once 'includes.php';</code><br />
</font>  <font color="#000000">makeIncludePath($includes);</font></p></blockquote>
<p><font color="#000000">I realise that </font><font color="#000000">by using my own object I lose the benefit of all the convenient methods defined in Zend_Conf_Ini, but for such a simple job, I might not feel the difference. Yet I am </font><font color="#000000">thinking about extending Zend_Conf_Ini with the method discussed above. I might be worth it. Find out more on the subject here:<br />
<a href="http://kanian77.wordpress.com/2007/11/06/using-config-part-2/">Using ZEND_Config Part 2</a></font></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/kanian77.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/kanian77.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kanian77.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kanian77.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kanian77.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kanian77.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kanian77.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kanian77.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kanian77.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kanian77.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kanian77.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kanian77.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kanian77.wordpress.com&blog=2054282&post=5&subd=kanian77&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kanian77.wordpress.com/2007/11/05/configuring-zend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1cea03b59b7d4d488bd796e423551e8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kanian77</media:title>
		</media:content>
	</item>
		<item>
		<title>Integrate Propel with Zend the Easy Way</title>
		<link>http://kanian77.wordpress.com/2007/11/05/how-do-i-integrate-propel-with-zend/</link>
		<comments>http://kanian77.wordpress.com/2007/11/05/how-do-i-integrate-propel-with-zend/#comments</comments>
		<pubDate>Mon, 05 Nov 2007 18:00:43 +0000</pubDate>
		<dc:creator>kanian77</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Propel]]></category>

		<guid isPermaLink="false">http://kanian77.wordpress.com/2007/11/05/how-do-i-integrate-propel-with-zend/</guid>
		<description><![CDATA[ Background
In his article &#8220;integrating propel with the Zend Framework&#8221; ,   Ralph Eggert   explains how one could integrate propel to his Zend application.  It&#8217;s interesting to see how  an  _autoload php function can be used to automatically load needed classes (propel,or Zend  classes) and thus avoid having [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kanian77.wordpress.com&blog=2054282&post=4&subd=kanian77&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h2> Background</h2>
<p>In his article <a href="http://devzone.zend.com/article/184-Integrating-Propel-with-the-Zend-Framework">&#8220;integrating propel with the Zend Framework&#8221; </a>, <a href="http://devzone.zend.com/member/253-Ralf-Eggert">  Ralph Eggert </a>  explains how one could integrate propel to his Zend application.  It&#8217;s interesting to see how  an  _autoload php function can be used to automatically load needed classes (propel,or Zend  classes) and thus avoid having to explicitly include the propel files in every controller that would need access to the model.</p>
<h2> From there</h2>
<p>One area that the article did not mention was, how does the app know which model will be used? I mean, let&#8217;s say a client clicks on the link &#8220;controller/action&#8221;, do I have to wait for the front controller to dispatch the request to the controller before knowing that it was called? That is, the entity referenced by the request is known explicitly by my application only when the requested action code is about to be executed.<br />
Before going further we have to make some assumption about our application. We will assume that each controller relates to one entity in our model. For example, the &#8220;apple&#8221; controller is the &#8220;apple&#8221; model&#8217;s controller.</p>
<h2> Use case</h2>
<p>Let&#8217;s say I want  to apply business logic that involves one more additional models(or should I say entity in the model?) before the controller&#8217;s action is called. Then I would need to know the controller(thus the model) mentinoed in the request URL before the the action is actually dispatched.</p>
<h2> Using a Plugin</h2>
<p>The Z<font color="#000000">end Framework plugin system provides a solution to this problem. The solution involves writting a plugin and registering it. The Zend Framework documentation says it better than me:</font></p>
<blockquote><p><font color="#000000">The controller architecture includes a plugin system that allows user code to be called when certain events occur in the controller process lifetime. The front controller uses a plugin broker as a registry for user plugins, and the plugin broker ensures that event methods are called on each plugin registered with the front controller.</font></p></blockquote>
<p><font color="#000000">The event I&#8217;m looking for is the </font><font color="#000000"><code>routeShutdown</code> event. It means that the router is done parsing the request URL and has populated the Request object with the controller name and action name. At this point I can use this code </font><font color="#000000"><code>$controllerName = $this-&gt;getRequest()-&gt;getControllerName();</code> to get the controller name. From there on, the logic  really depends on what you want to achieve and the naming convention of your model classes, among others. In my case, I renamed the ORM generated classes so that they have the same name as the controllers, only that they are camel cased. </font><font color="#000000">In fact I use the propel generated model classes as the abstraction layer to the database. The business logic, I will call the model service. This is what is done to the data that propel will give me from the database. </font><font color="#000000">Hence I could have controller &#8216;user&#8217; ,model &#8216;User&#8217;, and model service &#8216;UserService&#8217; . Here is the code for my plugin:</font></p>
<blockquote><p><font color="#000000"><code> public function routeStartup(Zend_Controller_Request_Abstract $request)</code><br />
<code> {</code><br />
<code> //$this-&gt;getResponse()-&gt;appendBody("&lt;p&gt;routeStartup() called&lt;/p&gt;\n");</code><br />
<code> }</code></font></p>
<p><font color="#000000">public function </font></p>
<p><font color="#000000"><code>routeShutdown(Zend_Controller_Request_Abstract $request)<br />
{<br />
$controllerName = $this-&gt;getRequest()-&gt;getControllerName();<br />
$modelClass = ucwords($controllerName).'.php';<br />
$modelServiceClass = ucwords($controllerName).'Service.php';</code></font></p>
<p><font color="#000000"><code>if (file_exists('path/to/your/app/propel/generated/files/modelClass'))<br />
{<br />
require_once($modelClass);</code></font></p>
<p><font color="#000000"><code>}</code></font></p>
<p><font color="#000000"><code>if (file_exists('path/to/your/app/modelServiceClass'))<br />
{</code></font><font color="#000000"><br />
<code>require_once($modelServiceClass);</code></font></p>
<p><font color="#000000"><code>}<br />
}</code></font></p>
<p><font color="#000000"><code>public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)<br />
{<br />
//$this-&gt;getResponse()-&gt;appendBody("dispatchLoopStartup() called\n");<br />
}</code></font></p>
<p><font color="#000000"><code>public function preDispatch(Zend_Controller_Request_Abstract $request)<br />
{<br />
//$this-&gt;getResponse()-&gt;appendBody("preDispatch() called\n");<br />
}</code></font></p>
<p><font color="#000000"><code>public function postDispatch(Zend_Controller_Request_Abstract $request)<br />
{<br />
//$this-&gt;getResponse()-&gt;appendBody("postDispatch() called\n");<br />
}</code></font></p>
<p><font color="#000000"><code>public function dispatchLoopShutdown()<br />
{<br />
//$this-&gt;getResponse()-&gt;appendBody("dispatchLoopShutdown() called\n");<br />
}<br />
}</code></font></p>
<p><font color="#000000"><a href="http://kanian77.pastebin.com/f74137023">Visit this link for better formatted listing of this code.</a></font></p></blockquote>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/kanian77.wordpress.com/4/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/kanian77.wordpress.com/4/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kanian77.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kanian77.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kanian77.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kanian77.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kanian77.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kanian77.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kanian77.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kanian77.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kanian77.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kanian77.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kanian77.wordpress.com&blog=2054282&post=4&subd=kanian77&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://kanian77.wordpress.com/2007/11/05/how-do-i-integrate-propel-with-zend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e1cea03b59b7d4d488bd796e423551e8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kanian77</media:title>
		</media:content>
	</item>
	</channel>
</rss>