contents/articles/27.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
----- title: "rdBaker: Bake your CakePHP application online" content-type: article timestamp: 1147081800 tags: "cakephp" ----- <p>Right after my <a href="http://base--/blog/view/26">last blog post</a> I decided to log on #cakephp on irc.freenode.org as usual, and gwoo pops in and says “h3raLd, you didn’t review rdBaker yet!”<br /> That’s right, I didn’t yet, so I may as well do it today.</p> <p>I remember hearing about rdBaker months ago, waaay before CakePHP 1.0, way before the RCs, I remember someone mentioning it on CakePHP user group in right after the bake.php script was created. <em>“How about having an online baking utility?”</em> – and that’s precisely what rdBaker is, a more <span class="caps">PHP</span>-ish version of bake.php, which runs like any other <span class="caps">PHP</span> scripts: in your browser.</p> <p>This cute little thing is obviously available for free on <a href="http://cakeforge.org/frs/?group_id=13&release_id=74">CakeForge</a> and is part of <a href="http://www.rd11.com">gwoo</a> ’s <a href="http://cakeforge.org/projects/rdos/">rdOpenSource</a> project which includes various other Cake-powered applications.<br /> I personally recommend new (and old) bakers to download them and play with them, try to understand how they were coded, because they can really teach you <em>a lot</em> on how to code a CakePHP application or website properly.</p> <p>So anyway, get your copy of rdBaker, unzip it and have a look at the <code>README.txt</code> file for the installation instructions:</p> <quote> <p>1. Place rdBaker in the root along side /cake_install/app.<br /> 2. chmod /cake_install/rdBaker/tmp to 0777<br /> 3. launch http://localhost/cake_install/rdBaker/</p> </quote> <p>Not too hard, innit?</p> <p><img src="http://base--/img/pictures/rdbaker.jpg" alt="" /></p> <p>Good. So you try accessing something like <code>http://localhost/php/test/cakephp/cake_test/rdBaker/</code> (that’s on my own local <span class="caps">WAMP</span> server) and you’ll get a nice page asking you to “supply your ingredients” via a simple form. <br /> Unlike its command line cousin, rdBaker doesn’t require you to fill in <em>all</em> the fields, but just the full path to the save directory (which is normally already filled in) and of course the name of the model (Post, User, Comment).<br /> Then you can select the type of output and choose whether you want to generate an empty controller, a scaffolded one or the <em>full</em> option including all the most common <acronym title="Create, Retrieve, Update, Delete"><span class="caps">CRUD</span></acronym> methods.<br /> Finally – if you like – you can enter any association or valitation rules for your model, then press the <em>Bake it!</em> button and voilá, in you’ll find three directories (controllers, models and views) in your save directory containing all the <acronym title="Model View Controller"><span class="caps">MVC</span></acronym> entities you need regarding a particular model:</p> <pre><code> rdBaker Result Array ( [0] => notes_controller.php created and written. Look in D:SERVERwwwphptestcakephpcake_testtmpcontrollers [1] => note.php created and written. Look in D:SERVERwwwphptestcakephpcake_testtmpmodels [2] => index.thtml created and written. Look in D:SERVERwwwphptestcakephpcake_testtmpviews/notes [3] => add.thtml created and written. Look in D:SERVERwwwphptestcakephpcake_testtmpviews/notes [4] => edit.thtml created and written. Look in D:SERVERwwwphptestcakephpcake_testtmpviews/notes [5] => view.thtml created and written. Look in D:SERVERwwwphptestcakephpcake_testtmpviews/notes ) </code></pre> <p>But there’s more! By checking the appropriate checkbox, you can get all the stuff packed in a zip file!</p> <p>Not bad at all, and fast as well.</p> <p>Now the bad things…<br /> The script works fine, but there’s something which could be improved, perhaps:</p> <ul> <li>If you choose to put everything in a zip file, the file will be named “baked_by_rdBaker.zip” – not a big deal, but maybe it could be personalized according to the model name entered.</li> <li>Regardless you want to add validation rules to your model or not, you’ll <em>always</em> find some validation rules for a <em>title</em> and <em>body</em> field. I checked and they are hardcoded in the template file (rdBaker/views/helpers/templates/full/model.txt):<br /> <pre><code> var $validate = array( 'title'=>VALID_NOT_EMPTY, 'body'=>VALID_NOT_EMPTY); </code></pre></li> <li>In the baked index.thtml view, there will always be a column named “Title”. This, again, is hardcoded in the template.</li> </ul> <p>Other than these things, everything seems to work fine. A really nice script!</p> |