<?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>cakebaker &#187; mvc</title>
	<atom:link href="http://cakebaker.42dh.com/tags/mvc/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakebaker.42dh.com</link>
	<description>baking cakes with CakePHP</description>
	<lastBuildDate>Mon, 19 Jul 2010 14:23:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>MVC with Javascript</title>
		<link>http://cakebaker.42dh.com/2007/03/17/mvc-with-javascript/</link>
		<comments>http://cakebaker.42dh.com/2007/03/17/mvc-with-javascript/#comments</comments>
		<pubDate>Sat, 17 Mar 2007 14:38:03 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[mvc]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/03/17/mvc-with-javascript/</guid>
		<description><![CDATA[Javascript was one of those things I tried to avoid up to now. I don&#8217;t know why, but somehow I disliked it (probably because it was a pain to use it in the early days of Javascript) ;-) Sure, I used a bit of Ajax here and there, but thanks to the CakePHP Ajax helper [...]]]></description>
			<content:encoded><![CDATA[<p>Javascript was one of those things I tried to avoid up to now. I don&#8217;t know why, but somehow I disliked it (probably because it was a pain to use it in the early days of Javascript) ;-)  Sure, I used a bit of Ajax here and there, but thanks to the CakePHP Ajax helper I didn&#8217;t had to touch the Javascript. </p>
<p>Lately, I decided to do an Ajax application and so I had to learn Javascript. To make my life easier, I decided to use the <a href="http://jquery.com">JQuery framework</a>. I have chosen JQuery over <a href="http://www.prototypejs.org">Prototype</a> because I heard many good things about JQuery, and the API documentation was (and still is) more intuitive. </p>
<p>Of course, my first attempt ended in a total mess. The result looked more like spaghetti than code ;-)  That&#8217;s when I recalled an <a href="http://cakebakery.de/2006/08/17/waschmittel-in-der-kuche/">article</a> (in German) about a Javascript MVC framework called <a href="http://jamal.moagil.de/">Jamal</a>, developed by <a href="http://teemow.com">Timo Derstappen</a>. From the Jamal website:</p>
<blockquote><p>
The MVC concept is easy to adopt for javascript </p>
<ul>
<li>Controller: Interaction with the user interface (events) </li>
<li>Model: Business Logic and AJAX calls </li>
<li>View: DOM, CSS modifications </li>
</ul>
</blockquote>
<p>That makes sense. So I had a closer look at Jamal. It looked nice, but it bothered me that you would have to use a CSS class &#8220;jamal&#8221; in the HTML code to make it work. So I wrote my own implementation called &#8220;jscake&#8221; which avoids that. You can find the first version in the <a href="http://cakebaker.42dh.com/downloads">downloads section</a>.</p>
<p>Let&#8217;s create a simple &#8220;Hello world&#8221; example with jscake. Our example (CakePHP) view will contain a link and a div to show the messages: </p>
<pre>
&lt;a href=""&gt;click&lt;/a&gt;
&lt;div id="messages"&gt;&lt;/div&gt;
</pre>
<p>First we create our model. All models are in the &#8220;$m&#8221; namespace (please correct me if that is the wrong term), which is a shortcut for &#8220;jscake.models&#8221;. So our model is called &#8220;$m.Example&#8221;. The model contains one function to return the text which should be displayed:</p>
<pre>
// app/webroot/js/models/example.js
$m.Example = {

    getText: function() {
        return "hello world";
    }
};
</pre>
<p>The view is similar to the model, it contains only one function, too. In the function the element with the id &#8220;messages&#8221; is located and the text appended to that element. Similar to the models the views are in the &#8220;$v&#8221; namespace.</p>
<pre>
// app/webroot/js/views/examples.js
$v.Examples = {

    showMessage: function(message) {
        $('#messages').append(message);
    }
};
</pre>
<p>Last, but not least, we have to create the controller. The index function is automatically called when the JQuery ready event occurs. In this function we simply say that when someone clicks on the link, the other function of the controller (sayHelloWorld) should be executed.</p>
<pre>
//app/webroot/js/controllers/examples_controller.js
$c.ExamplesController = {

    index: function() {
        $('a').click(this.sayHelloWorld);
    },

    sayHelloWorld: function() {
        $v.Examples.showMessage($m.Example.getText());

        return false;
    }
};
</pre>
<p>To make our example work we have to include all needed Javascript files in our view, with CakePHP 1.2 it looks like:</p>
<pre>
&lt;?php $javascript-&gt;link(array('jquery-1.1.2', 'jscake', 'controllers/examples_controller',
'models/example', 'views/examples', 'start'), false); ?&gt;
&lt;a href=""&gt;click&lt;/a&gt;
&lt;div id="messages"&gt;&lt;/div&gt;
</pre>
<p>Have fun with jscake! Feedback is welcome :)</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2007/03/17/mvc-with-javascript/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Should you use Model::query() in the controller?</title>
		<link>http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/</link>
		<comments>http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/#comments</comments>
		<pubDate>Mon, 26 Feb 2007 09:49:07 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[mvc]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/</guid>
		<description><![CDATA[The query() function of the model is sometimes very practical as it allows you to execute any SQL statement you want. But to me it seems it is often used in a &#8220;wrong&#8221; way (I have to include myself *g*), in a way which works but is not that clean. I am talking about calling [...]]]></description>
			<content:encoded><![CDATA[<p>The query() function of the model is sometimes very practical as it allows you to execute any SQL statement you want. But to me it seems it is often used in a &#8220;wrong&#8221; way (I have to include myself *g*), in a way which works but is not that clean. I am talking about calling query() from the controller:</p>
<pre>
$this-&gt;MyModel-&gt;query('Here comes the SQL statement');
</pre>
<p>Sure, following the Cake conventions this is a valid usage of query(), as the function is public. But it introduces database-related code to the controller, which is a violation of the <a href="http://en.wikipedia.org/wiki/Model-view-controller">MVC pattern</a>. </p>
<p>I think a cleaner solution is to move the SQL statement to the model. So the snippet from above can be refactored to:</p>
<pre>
// in the model
function doSomething() {
    $this-&gt;query('Here comes the SQL statement');
}

// in the controller
$this-&gt;MyModel-&gt;doSomething();
</pre>
<p>Ok, this solution needs more code, but it comes with some additional advantages:</p>
<ul>
<li>it is easier to test</li>
<li>it is more readable (at least if you give the function a better name than I did)</li>
<li>the query can be re-used without copy &#038; paste in other actions/controllers</li>
</ul>
<p>What do you think about this approach?</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2007/02/26/should-you-use-modelquery-in-the-controller/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>CakePHP is the number 3 of PHP MVC frameworks&#8230;</title>
		<link>http://cakebaker.42dh.com/2006/01/06/cakephp-is-the-number-3-of-php-mvc-frameworks/</link>
		<comments>http://cakebaker.42dh.com/2006/01/06/cakephp-is-the-number-3-of-php-mvc-frameworks/#comments</comments>
		<pubDate>Fri, 06 Jan 2006 12:28:56 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[comparison]]></category>
		<category><![CDATA[general]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.cakebaker.42dh.com/?p=39</guid>
		<description><![CDATA[&#8230; at least according to mustaphas post Top 10 PHP MVC frameworks. He writes about CakePHP: CakePHP is very promising, the only problem &#8211; really, I don&#8217;t know if it is a problem &#8211; is: the development process is very slow. Hm, I cannot say if the development process is slow compared with other frameworks, [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230; at least according to mustaphas post <a href="http://www.mustap.com/phpzone_post_73_top-10-php-mvc-frameworks">Top 10 PHP MVC frameworks</a>. He writes about CakePHP:</p>
<blockquote><p>
CakePHP is very promising, the only problem &#8211; really, I don&#8217;t know if it is a problem &#8211; is: the development process is very slow.
</p></blockquote>
<p>Hm, I cannot say if the development process is slow compared with other frameworks, but what I see is that there is a steady progress. What do you think?</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2006/01/06/cakephp-is-the-number-3-of-php-mvc-frameworks/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
