<?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>martian arts &#187; php</title>
	<atom:link href="http://blog.martian-arts.org/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.martian-arts.org</link>
	<description>webcode experiments</description>
	<lastBuildDate>Mon, 14 Nov 2011 19:40:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Understanding MVC</title>
		<link>http://blog.martian-arts.org/understanding-mvc/</link>
		<comments>http://blog.martian-arts.org/understanding-mvc/#comments</comments>
		<pubDate>Fri, 16 Sep 2011 23:56:06 +0000</pubDate>
		<dc:creator>y_nk</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.martian-arts.org/?p=61</guid>
		<description><![CDATA[For a project i worked on, i had to build a php website from scratch. The timing was good, and the project was tiny enough to let some freestyle happen. I had the chance to work with great people before, and had lots of talks about the zend framework or symfony. I heard a lot [...]]]></description>
			<content:encoded><![CDATA[<p>For a project i worked on, i had to build a php website from scratch. The timing was good, and the project was tiny enough to let some freestyle happen.<span id="more-61"></span></p>
<p>I had the chance to work with great people before, and had lots of talks about <a href="http://framework.zend.com/" target="_blank">the zend framework</a> or <a href="http://www.symfony-project.org/" target="_blank">symfony</a>. I heard a lot about their processes, their pros and cons, but didn&#8217;t get the point with using those big engines for small/medium projects.</p>
<p>It was a good time for me. I enjoyed a lot scratching my head on problems that i knew Zend or Symfo writers had. About the structure, about performances. Since i still feel newbie with php, i didn&#8217;t matter that much on execution&#8217;s performances.</p>
<p>Since my project folder was fully empty, I first put some basics concepts, such as a lib folder that would have contained common framework code, a src folder that would have contained my app code, and a www folder in which i would have put public files.</p>
<p>Then, i started with a single monolithic static object called &#8220;App&#8221; in that lib/ folder, and a index.php in www/ that triggers my App::dispatch method, with also an .htaccess file that redirects any non-physical request to the index.php file.</p>
<p>After that, my strategy was to parse the url with a single type of route which was <code>/{controller}/{action}/{parameters}</code>.</p>
<p>Project changed, and a second app was also needed : the backend. I added a src/ folder that would contain a specific folder for each application handled by the framework. Since i didn&#8217;t know the best way to link urls to specific applications, i built a simple file which was called &#8220;config.php&#8221; containing an associative array was describing this relationship between urls and application.</p>
<p>When it was about to choose how i would do to call my actions, i started to understand why framework suffixes controller and action names : they probably needed to avoid multiple definition that could occurs between lib code and app code that couldn&#8217;t be under control.</p>
<p>I was not very happy with having a big structure with controller objects that had actions as methods, it looked very huge to me. As i&#8217;m a wordpress fan, i decided to use filesystem&#8217;s file as controller&#8217;s concept and simple global functions as action.</p>
<p>I only had to have function index($params = null) {} in my src/front/controllers/index.php file and it was working ! YAY ! After that, all was easy :) My process was kind of defined, so it was only about pimping it up&#8230; and that&#8217;s what i did !</p>
<p>I added a functions.php file which acted as a starter file of each application, and so i learnt about the &#8220;pre&#8221; and &#8220;post&#8221; dispatch concept i heard so much about from <a href="http://www.kosmidis.me/" target="_blank">panosru</a>.</p>
<p>I also changed the config.php file to a more simple xml file that would be parsed automatically&#8230; MUCH easier, and also inspired by the Zend&#8217;s ini file. I still ask myself if xml is the best format. I still prefer it from others, but i&#8217;ll like to consider using json, yaml or ini too.</p>
<p><a href="http://arnaud-tanielian.fr/" target="_blank">Danetag</a> told me a long time ago about orms, and about doctrine was working. I wanted to try myself, something more humble of course. I wrote a first &#8220;Model&#8221; object that would contain all the logic of a single abstract model object. I thought it was logic to have a static &#8220;get&#8221; method, since any model object should perform a get action to a database. Then, the instances should be able to be saved or deleted. The save method should know if an insert or update query should occur. My implementation was working fine, but i was too deep in the code to see that i would had to call Model::get any time i would get something. That was very bad because i was expecting something like User::get, or Admin::get&#8230; Hopefully for myself, php keeps inheritance of static methods. It&#8217;s still a strange and disturbing thing to me but it looks like php won&#8217;t change, since it&#8217;s still working wih php6.</p>
<p>I&#8217;m still not able to make NN requests, and i&#8217;m not that confident with execution&#8217;s performances. But as a piece of learning, i really enjoy what i did. I learnt a lot, and i highly recommand to try this trip into mvc. You&#8217;re in front of choices that others took before, you&#8217;re passing through some state of mind they probably had, and you take decisions that may be different than them. If the timing is good, try yourself, you&#8217;ll know what i meant ;)</p>
<p>I&#8217;m currently re-writing the url parsing, to let the coder choose the url pattern. I also want to taste the difficulty of i18n better than i tried to do (aka &#8216;DIY&#8217;).</p>
<p>I put my code on <a href="https://github.com/ynk/martian-phpmvc" target="_blank">github</a>, if you give it a try, feel free to comment.</p>
<p>Don&#8217;t be rude, it&#8217;s a 0.1 alpha :)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.martian-arts.org/understanding-mvc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  blog.martian-arts.org/category/php/feed/ ) in 0.22326 seconds, on Feb 7th, 2012 at 9:43 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 7th, 2012 at 10:43 am UTC -->
