<?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>nerdnotes.org &#187; cakephp</title>
	<atom:link href="http://nerdnotes.org/category/nerdnotes/cakephp/feed/" rel="self" type="application/rss+xml" />
	<link>http://nerdnotes.org</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 17 Dec 2010 22:55:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Cakephp logger plugin</title>
		<link>http://nerdnotes.org/2010/04/cakephp-logger-plugin/</link>
		<comments>http://nerdnotes.org/2010/04/cakephp-logger-plugin/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 09:32:19 +0000</pubDate>
		<dc:creator>Bram</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[nerdnotes]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[logger]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[tail -f]]></category>

		<guid isPermaLink="false">http://nerdnotes.org/?p=137</guid>
		<description><![CDATA[For one of my projects, I wanted to have a live view of the cake log file in the admin page. What started out as some hacked controller methods, turned into a plugin that can be inserted in any random cake app. Ingredients: a php implementation of the unix tail command, by Paul Gregg a [...]]]></description>
			<content:encoded><![CDATA[<p>For one of my projects, I wanted to have a live view of the cake log file in the admin page. What started out  as some hacked controller methods, turned into a plugin that can be inserted in any random cake app. Ingredients:</p>
<ul>
<li>a <a href="http://www.pgregg.com/projects/php/code/tail-10.php">php implementation</a> of the unix tail command, by <a href="http://www.pgregg.com">Paul Gregg</a></li>
<li>a session variable to keep track of what part of the log file has been sent</li>
<li>some jquery code (using the <a href="http://www.360innovate.co.uk/blog/2009/03/periodicalupdater-for-jquery/">periodicalupdater</a> plugin) that adds new lines to a div element as they appear in the log file, scrolls down so the new content becomes visible</li>
</ul>
<p>The online demo consist of a <a href="http://cakephp-logger-demo.nerdnotes.org/">bare cake &#8216;install&#8217;</a> with the plugin dropped into the plugins directory. As you can see, there&#8217;s no models, views or controllers. Visiting the app will actually log some messages to the debug log. To monitor the log file, visit the <a href="http://cakephp-logger-demo.nerdnotes.org/logger/loggers/">plugin path</a>.<br />
I&#8217;ve also added two links that lets you add lines to the debug log.</p>
<p>The theoretical advantage of using a plugin is that you can simply drop the code in the plugins directory and voila! it works!<br />
 In practice, it&#8217;s quite annoying that plugins are similar to, but not exactly structured like cake apps. For example: images and js code should be placed in the vendors folder instead of webroot. Secondly: app_model.php and app_controller.php need to be prefixed by the (singular) plugin name.<br />
Finally, it&#8217;s not clear how to integrate the plugin with your actual cake app. Like using the app&#8217;s authentication methods to only allow &#8216;admin&#8217; users to view the log file.</p>
<p>I&#8217;m actually not sure a plugin is the right way of implementing an online &#8216;tail -f&#8217;. A component might do a better job. What do you think?</p>
<p> <a href="http://cakephp-logger-demo.nerdnotes.org/logger/loggers/">Online demo</a></p>
<p>The plugin can be <a href="http://nerdnotes.org/wp-content/uploads/2010/04/logger.tgz">downloaded here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nerdnotes.org/2010/04/cakephp-logger-plugin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cakeshell</title>
		<link>http://nerdnotes.org/2010/03/cakeshell/</link>
		<comments>http://nerdnotes.org/2010/03/cakeshell/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 13:04:34 +0000</pubDate>
		<dc:creator>Bram</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[nerdnotes]]></category>

		<guid isPermaLink="false">http://nerdnotes.org/?p=133</guid>
		<description><![CDATA[I&#8217;ve written a little wrapper script to ease the execution of cake shells. Just by creating symbolic links, you can turn any custom) cake shell into a shell command that can be called from any location. Ie: you don&#8217;t have to cd to your cake app directory. Just make sure the symlink is in your [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve written a little wrapper script to ease the execution of cake shells. Just by creating symbolic links, you can turn any custom) cake shell into a shell command that can be called from any location. Ie: you don&#8217;t have to cd to your cake app directory. Just make sure the symlink is in your $PATH.<br />
<code><br />
$ ./cakeshell<br />
Error: script should be symlinked<br />
cakeshell 0.1 - (c)2010 nerdnotes.org</p>
<p>This wrapper script is built in order to ease running cake shells.</p>
<p>Usage:<br />
The script should be located somewhere your cake directory structure.<br />
Make sure you configure the relative path of the cake script from the<br />
directory this script lives in (REL_CAKE_PATH).</p>
<p>For each of the shells you want to be available, create a symlink to<br />
./cakeshell with the name of the cake shell you want to execute</p>
<p>Example*<br />
*using some real world paths here</p>
<p>To simplify the following cake shell call:</p>
<p>./cake/console/cake bake</p>
<p>You'll need to do this once:</p>
<p>cd ~/bin<br />
ln -s ../public_html/cakesite/cakeshell bake</p>
<p>If ~/bin is in your PATH, you can simply run the bake script from anywhere</p>
<p></code><br />
That&#8217;s the output, here&#8217;s the <a href="/wp-content/cakeshell.txt">script itself</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nerdnotes.org/2010/03/cakeshell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP Email component</title>
		<link>http://nerdnotes.org/2009/10/cakephp-email-component/</link>
		<comments>http://nerdnotes.org/2009/10/cakephp-email-component/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 22:11:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[nerdnotes]]></category>
		<category><![CDATA[component]]></category>
		<category><![CDATA[phpmailer]]></category>

		<guid isPermaLink="false">http://nerdnotes.org/?p=120</guid>
		<description><![CDATA[This is quite a simple component that integrates PHPMailer with CakePHP. Save the following code to /app/controllers/components/email.php In addition to that, make sure phpmailer is installed in /app/vendors/phpmailer. I just extracted the phpmailer archive in /app/vendors/ and created a symlink: $ tar xzf PHPMailer_v5.0.2.tar.gz $ ln -s PHPMailer_v5.0.2 phpmailer Usage In your controller code, make [...]]]></description>
			<content:encoded><![CDATA[<p>This is quite a simple component that integrates <a href="http://phpmailer.worxware.com/index.php?pg=phpmailer">PHPMailer</a> with <a href="http://cakephp.org">CakePHP</a>. Save the following code to /app/controllers/components/email.php</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php 

App::import('Vendor', 'PhpMailer', array('file' =&gt; 'phpmailer' . DS . 'class.phpmailer.php'));

/*
    Depends on &quot;unhtml&quot;
*/

class EmailComponent extends PHPMailer
{
	// phpmailer
	var $Mailer = 'sendmail'; // choose 'sendmail', 'mail', 'smtp'
	var $unhtml_bin = '/usr/bin/unhtml';

	// component
	var $controller;

	function startup( &amp;$controller )
	{
		$this-&gt;controller = &amp;$controller;
	}

	function renderBody($view)
	{
		// render the view and use its output to set the body text of the email
		$this-&gt;Body = $this-&gt;controller-&gt;render('emails/' . $view, 'email');

		// reset the output of the controller
		$this-&gt;controller-&gt;output = '';

		// create plain text version of the email
		//
		// create temporary files
		$htmlfile = tempnam(TMP, 'htmlfile');
		$textfile = tempnam(TMP, 'textfile');

		// write html to temporary file
		file_put_contents($htmlfile, $this-&gt;Body);

		// convert the html file to plain text
		$cmd = &quot;cat $htmlfile | $this-&gt;unhtml_bin &gt; $textfile&quot;;
		system($cmd);

		// set the plain text body of the email
		$this-&gt;AltBody = file_get_contents($textfile);

		// remove temporary files
		unlink($htmlfile);
		unlink($textfile);
	}
}

?&gt;
</pre>
<p>In addition to that, make sure phpmailer is installed  in /app/vendors/phpmailer. I just extracted the phpmailer archive in /app/vendors/ and created a symlink:<br />
<code><br />
$ tar xzf PHPMailer_v5.0.2.tar.gz<br />
$ ln -s PHPMailer_v5.0.2 phpmailer<br />
</code><br />
<strong>Usage</strong><br />
In your controller code, make sure the component is included by adding it to the components array:</p>
<pre class="brush: php; title: ; notranslate">
var $components = array('Email');
</pre>
<p>In app/views/layouts, create a new layout called email.ctp. It should contain something like:</p>
<pre class="brush: php; title: ; notranslate">
&lt;html&gt;
&lt;body&gt;
&lt;?php echo $content_for_layout; ?&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>Let&#8217;s send some emails!</strong><br />
In controller snippet, the renderBody(&#8216;test&#8217;) call will create a html email from the view in app/views/users/emails/test.ctp. Additionally, a plain text version will be generated using &#8216;unhtml&#8217;. Unhtml has a package in the Ubuntu / Debian repository.<br />
The action works just like rendering a normal view. The $this->Email object is just an instance of PHPMailer and all PHPMailers&#8217; methods and properties apply.</p>
<pre class="brush: php; title: ; notranslate">
function testmail()
{
	// *Some notes*
	// Email methods:    http://phpmailer.worxware.com/index.php?pg=methods
	// Email properties: http://phpmailer.worxware.com/index.php?pg=properties
	//
	// Email configuration is done in /app/controllers/components/email.php

	$this-&gt;set(compact('some', 'vars'));

	// the email content is just a (html) view in app/views/{controller}/emails/testmail.ctp
	$this-&gt;Email-&gt;renderBody('test');

	// subject
	$this-&gt;Email-&gt;Subject = 'Test from example.com';

	// sender
	$this-&gt;Email-&gt;SetFrom('test@example.com', 'Test');

	// recipients
	$this-&gt;Email-&gt;AddAddress('joe@example.com', 'Joe');
	$this-&gt;Email-&gt;AddAddress('jane@example.com', 'Jane');

	// send!
	$this-&gt;Email-&gt;Send();
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://nerdnotes.org/2009/10/cakephp-email-component/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cakephp ThumbnailHelper</title>
		<link>http://nerdnotes.org/2009/04/cakephp-thumbnailhelper/</link>
		<comments>http://nerdnotes.org/2009/04/cakephp-thumbnailhelper/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 17:44:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[nerdnotes]]></category>

		<guid isPermaLink="false">http://nerdnotes.org/2009/04/07/cakephp-thumbnailhelper/</guid>
		<description><![CDATA[This thumbnail helper is based on the one published by Studio Canaria. Additional features are multiple size caching and an extra method which is a truly drop-in replacement for $html->image(). Usage: Installation: Download thumbnail.txt Rename it to thumbnail.php and place it in /app/views/helpers/ download phpThumb() Extract the phpThumb archive in a directory named /app/vendors/phpthumb/ Add [...]]]></description>
			<content:encoded><![CDATA[<p>This thumbnail helper is based on the one published by <a href="http://www.studiocanaria.com/articles/cakephp_thumbnail_helper">Studio Canaria</a>. Additional features are multiple size caching and an extra method which is a truly drop-in replacement for $html->image().<br />
Usage:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

echo $thumbnail-&gt;image('picture.jpg', array(
 	'alt' =&gt; 'test thumbnail',
 	'width' =&gt; '100',
 	'height' =&gt; '75'
 	)
 );

// result:
// &lt;img src=&quot;/img/thumbs/100x75/picture.jpg&quot;
//	alt=&quot;test thumbnail&quot; height=&quot;75&quot; width=&quot;100&quot;&gt;

?&gt;
</pre>
<p>Installation:</p>
<ul>
<li>Download <a href='http://nerdnotes.org/wp-content/uploads/2009/04/thumbnail.txt' target="_blank" title='thumbnail.txt'>thumbnail.txt</a></li>
<li>Rename it to thumbnail.php and place it in /app/views/helpers/</li>
<li><a href="http://phpthumb.sourceforge.net/#download">download</a> <a href="http://phpthumb.sourceforge.net">phpThumb()</a></li>
<li>Extract the phpThumb archive in a directory named /app/vendors/phpthumb/</li>
<li>Add &#8216;Thumbnail&#8217; to the &#8216;helpers&#8217; array your controller</li>
<li>Create a directory named &#8216;thumbs&#8217; in /app/webroot/img/. Make sure it&#8217;s writable for the webserver.</li>
</ul>
<p>That&#8217;s it!<br />
In the above example, the thumb helper will first check if there is a file named /app/webroot/img/thumbs/100&#215;75/picture.jpg. If it isn&#8217;t there yet, it will instantiate phpThumb and create the thumbnail.<br />
For more advanced usage, there&#8217;s also the render() method. It will give you the flexibility to use images located outside /app/webroot/img and also make use of most of the <a href="http://phpthumb.sourceforge.net/demo/docs/phpthumb.readme.txt">phpThumb options</a>.<br />
Advanced example:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

$thumb = $thumbnail-&gt;render(
	$data['Picture']['path'],
	array(
		'w' =&gt; 320,
		'h' =&gt; 200,
		'ra' =&gt; 10
	),
	'5271a9e66c99c84c092d7fd81cebcd57'
);

echo $html-&gt;image($thumb);

?&gt;
</pre>
<p>This will generate a picture named /app/webroot/img/thumbs/320&#215;200/5271a9e66c99c84c092d7fd81cebcd57.jpg, which is a 10 degrees rotated thumbnail of the original image specified with $data['Picture']['path'].</p>
]]></content:encoded>
			<wfw:commentRss>http://nerdnotes.org/2009/04/cakephp-thumbnailhelper/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>explorerTree demo files</title>
		<link>http://nerdnotes.org/2009/04/explorertree-demo-files/</link>
		<comments>http://nerdnotes.org/2009/04/explorertree-demo-files/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 15:35:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[nerdnotes]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://nerdnotes.org/2009/04/06/tree-demo-files/</guid>
		<description><![CDATA[To save you some typing, this archive contains a working example of the tree helper code described in the bakery. The archive includes cake 1.2, three images and jquery. In the js-code, some hard-coded paths were corrected. It also contains a file named tree.sql which contains a dump of the database including some sample data.]]></description>
			<content:encoded><![CDATA[<p><img src='http://nerdnotes.org/wp-content/uploads/2009/04/tree.png' alt='tree.png' /><br />
To save you some typing, <a href="http://nerdnotes.org/wp-content/uploads/2009/04/tree.tgz">this archive</a> contains a working example of the <a href="http://bakery.cakephp.org/articles/view/creating-an-explorer-like-navigation">tree helper</a> code described in the bakery. The archive includes cake 1.2, three images and jquery. In the js-code, some hard-coded paths were corrected. It also contains a file named tree.sql which contains a dump of the database including some sample data.</p>
]]></content:encoded>
			<wfw:commentRss>http://nerdnotes.org/2009/04/explorertree-demo-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>cakephp, user_dir and mod_rewrite</title>
		<link>http://nerdnotes.org/2009/04/cakephp-user_dir-and-mod_rewrite/</link>
		<comments>http://nerdnotes.org/2009/04/cakephp-user_dir-and-mod_rewrite/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 08:53:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[nerdnotes]]></category>

		<guid isPermaLink="false">http://nerdnotes.org/2009/04/02/cakephp-user_dir-and-mod_rewrite/</guid>
		<description><![CDATA[Here&#8217;s a little note on getting a cakephp app working in your public_html directory. In order to get the mod_rewrite configuration working, add a RewriteBase rule to the .htaccess files in the cakephp source. If your app is located in /home/me/public_html/cakesite/ and the URL to the site is http://host/~me/cakesite you&#8217;ll need to change the following [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little note on getting a cakephp app working in your public_html directory. In order to get the mod_rewrite configuration working, add a RewriteBase rule to the .htaccess files in the cakephp source. If your app is located in /home/me/public_html/cakesite/ and the URL to the site is http://host/~me/cakesite you&#8217;ll need to change the following .htaccess files:</p>
<blockquote><p>
/home/me/public_html/cakesite/.htaccess<br />
/home/me/public_html/cakesite/app/webroot/.htaccess
</p></blockquote>
<p>Add the following line to these files, just below the line stating &#8220;RewriteEnginge On&#8221;:</p>
<pre class="brush: css; title: ; notranslate">
RewriteBase /~me/cakesite/
</pre>
<p>For example, the first .htaccess file will look like:</p>
<pre class="brush: css; title: ; notranslate">
&lt;ifModule mod_rewrite.c&gt;
	RewriteEngine on
	RewriteBase /~me/cakesite/
	RewriteRule    ^$ app/webroot/    [L]
	RewriteRule    (.*) app/webroot/$1 [L]
&lt;/ifModule&gt;
</pre>
<p><strong>Bonus notes with instructions for Debian/Ubuntu systems</strong><br />
You should have mod_rewrite enabled:</p>
<blockquote><p>
$ sudo a2enmod rewrite<br />
$ sudo /etc/init.d/apache2 force-reload
</p></blockquote>
<p>To make sure the use of .htaccess files is actually allowed. In the Directory section of your apache configuration, there should be a line like:</p>
<blockquote><p>
AllowOverride FileInfo
</p></blockquote>
<p>Also, be sure to force-reload Apache after making this change.</p>
]]></content:encoded>
			<wfw:commentRss>http://nerdnotes.org/2009/04/cakephp-user_dir-and-mod_rewrite/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Combining Modalbox &amp; CakePHP</title>
		<link>http://nerdnotes.org/2008/02/combining-modalbox-cakephp/</link>
		<comments>http://nerdnotes.org/2008/02/combining-modalbox-cakephp/#comments</comments>
		<pubDate>Thu, 28 Feb 2008 13:17:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[nerdnotes]]></category>

		<guid isPermaLink="false">http://nerdnotes.org/2008/02/28/combining-modalbox-cakephp/</guid>
		<description><![CDATA[I&#8217;m pretty sure this can be implemented more elegantly, but I&#8217;ll describe my attempt to unite Modalbox with CakePHP 1.2. First example &#8211; a modal box view This example shows the steps I&#8217;ve taken to flavour a freshly baked cake app with modalbox. The starting point is a customer model, a controller and some basic [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://modalbox-cakephp-demo.nerdnotes.org"><img src='http://nerdnotes.org/wp-content/uploads/2008/02/cakephp-modalbox.thumbnail.png' class='alignright' title='demo included!' alt='demo included!' /></a>I&#8217;m pretty sure this can be implemented more elegantly, but I&#8217;ll describe my attempt to unite <a href="http://www.wildbit.com/labs/modalbox/">Modalbox</a> with <a href="http://cakephp.org">CakePHP 1.2</a>.</p>
<p><strong>First example &#8211; a modal box view</strong><br />
This example shows the steps I&#8217;ve taken to flavour a freshly baked cake app with modalbox. The starting point is a customer model, a controller and some basic index, view and edit views.<br />
Showing a cakephp view in a modalbox, is just a few snippets away. Just make sure you include prototype, scriptaculous and the modalbox javascript and the modalbox css file in the default layout&#8230;</p>
<pre class="brush: php; title: ; notranslate">
/app/views/layouts/default.ctp:
echo $html-&gt;css('modalbox');
echo $javascript-&gt;link('prototype');
echo $javascript-&gt;link('scriptaculous.js?load=effects');
echo $javascript-&gt;link('modalbox');
</pre>
<p>Then create the appropiate link to the view you want to load inside the modalbox. For example, if you want to show customer details from the customers/index.ctp view:</p>
<pre class="brush: php; title: ; notranslate">
# ...somewhere in the loop that lists customers:
echo $html-&gt;link('View', array('action' =&gt; 'view', $customer['Customer']['id']), array('title' =&gt; 'Customer details', 'onclick' =&gt; &quot;Modalbox.show(this.href, {title: this.title, width: 400}); return false;&quot;));
</pre>
<p>Make sure you use the RequestHandler component so that the customer view is displayed in the ajax.ctp instead of the default.ctp layout. You can do this by making sure the following line is in /app/app_controller.php:</p>
<pre class="brush: php; title: ; notranslate">
var $components = array('RequestHandler');
</pre>
<p>And&#8230; there you go! When you click the view link, the modalbox slides in, while the rest of the page dims to gray. When you hit the escape button, click the little &#8216;X&#8217; or click anywhere in the gray area, the modal box slides back where it came from.</p>
<p><strong>Ok, now forms!</strong><br />
<span id="more-92"></span><br />
This is where the example pages don&#8217;t seem to apply anymore. Or&#8230; this is where my concept of AJAX, CakePHP, Modalbox, etc. is fundamentally wrong&#8230; you tell me!</p>
<p>By calling an &#8216;edit&#8217; view instead of the &#8216;view&#8217; view, you&#8217;ve got yourselves a form inside the modalbox! Also very nice!<br />
After submitting the edit form, you&#8217;ll get redirected to the index page again. That&#8217;s when the form validates.<br />
Wait until you omit a required field. Instead of the index page, you get redirected to the edit form itself rendered in the ajax layout. There&#8217;s no single line of code yet that makes sure that the form will end up in the same modalbox.<br />
<!-- adman --><br />
To solve this, you need to replace the $form->create call in the edit view by $ajax->form. The form, starting with the tag generated by the Ajax helper, will submit using XMLHttpRequest instead of a normal HTTP request. In this way, the modalbox stays open and will be filled with whatever the form returns!</p>
<p>This was the form-helper call:</p>
<pre class="brush: php; title: ; notranslate">
echo $form-&gt;create('Customer');
</pre>
<p>&#8230;and the ajax-helper equivalent:</p>
<pre class="brush: php; title: ; notranslate">
echo $ajax-&gt;form('edit', 'post', array(
    'model'    =&gt; 'Customer',
    'url'      =&gt; array( 'controller' =&gt; 'customers', 'action' =&gt; 'edit'),
    'update'   =&gt; 'MB_content'
));
</pre>
<p>In order to make the Ajax helper available in the view, make sure you have included it in the controller:</p>
<pre class="brush: php; title: ; notranslate">
var $helpers    = array('Html','Javascript', 'Ajax');
</pre>
<p><em>I&#8217;m still wondering why the calls aren&#8217;t a little bit more alike&#8230;</em></p>
<p>This brings us one step closer&#8230;. or one step too far??<br />
All content will be rendered inside the modalbox. We need to tell modalbox when it&#8217;s not needed anymore. For example, when the form validated.</p>
<p>This can be done with a small javascript function that we define in the Default.ctp layout:</p>
<pre class="brush: php; title: ; notranslate">
function closeModalbox()
{
	if ($('closeModalbox')) {
		// hide the modal box
		Modalbox.hide();
		// refresh the current page
		location.reload(true);
	} else {
		// resize to content (in case of validation error messages)
		Modalbox.resizeToContent()
	}
	return true;
}
</pre>
<p>The function checks if there&#8217;s a div element with id=&#8221;closeModalbox&#8221;. If that is the case, it will close the modalbox and refresh the current page. Which, in itself is not so Ajax&#8230;.(but it works great!)<br />
If it can&#8217;t find the div element, it will resize the modalbox to it&#8217;s fresh content. To make sure the function is called, we can hook it into the Ajax form by adding the following line to the options array:</p>
<pre class="brush: php; title: ; notranslate">
'complete' =&gt; 'closeModalbox()'
</pre>
<p>In the edit view, we need to make sure that the closeModalbox-div is echoed conditionally:</p>
<pre class="brush: php; title: ; notranslate">
if (isset($closeModalbox) &amp;&amp; $closeModalbox) echo &quot;&lt;div id='closeModalbox'&gt;&lt;/div&gt;&quot;;
</pre>
<p>The $closeModalbox variable is, in his turn set from the controller after the data is successfully saved.</p>
<p>Last, but not least&#8230;. it&#8217;s relatively simple to be able to fall back to a non-ajax form.</p>
<p><strong>Demo</strong><br />
And since you probably allready lost the overview, here&#8217;s the <a href='http://nerdnotes.org/wp-content/uploads/2008/02/modalbox-cakephp-demo.tar.gz' title='modalbox-cakephp-demo'> complete source code</a> and&#8230;. a <a href="http://modalbox-cakephp-demo.nerdnotes.org">demo</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://nerdnotes.org/2008/02/combining-modalbox-cakephp/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>Howto start your CakePHP project in Subversion</title>
		<link>http://nerdnotes.org/2007/12/howto-start-your-cakephp-project-in-subversion/</link>
		<comments>http://nerdnotes.org/2007/12/howto-start-your-cakephp-project-in-subversion/#comments</comments>
		<pubDate>Wed, 05 Dec 2007 22:31:57 +0000</pubDate>
		<dc:creator>Bram</dc:creator>
				<category><![CDATA[cakephp]]></category>

		<guid isPermaLink="false">http://91</guid>
		<description><![CDATA[This howto will demonstrate how to start your cakephp project from scratch, taking advantage of subversions &#8220;externals definition&#8221;. The result will be a basic CakePHP directory structure with only the &#8220;/app&#8221; part under your svn control and the other directories linked to a specified revision of cakephp. Once setup, if you do a &#8216;svn chekout&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p>This howto will demonstrate how to start your cakephp project from scratch, taking advantage of subversions &#8220;externals definition&#8221;. The result will be a basic CakePHP directory structure with only the &#8220;/app&#8221; part under your svn control and the other directories linked to a specified revision of cakephp. Once setup, if you do a &#8216;svn chekout&#8217; of your project, you will get all the files at the right location, so no need to merge your &#8216;/app &#8216; with the contents of a tarbal which you downloaded from the <a href="http://cakephp.org">CakePHP website</a>.</p>
<p>Let&#8217;s get started!</p>
<p>First, we create a temporary directory structure, just for the purpose of importing it:</p>
<pre class="brush: css; title: ; notranslate">
$ mkdir temp
$ mkdir temp/mynewproject
$ mkdir temp/mynewproject
$ svn import -m &quot;New import&quot; temp file:///home/me/subversion/
# remove the temporary directory structure
$ rm -rf temp
</pre>
<p>Now, we checkout a working copy:</p>
<pre class="brush: css; title: ; notranslate">
$ cd ~/src
$ svn checkout file:///home/me/subversion/mynewproject
</pre>
<p>Ok, this just bought us an empty directory managed by subversion!! Let&#8217;s fill it with the use of some magic: Externals. We will create an externals definition for the directory. It will point to the current cakephp1.2 release, which is 5875 at time of writing.</p>
<pre class="brush: css; title: ; notranslate">
$ cd mynewproject
$ svn propedit svn:externals .
</pre>
<p>This will fire up your text editor with an empty text file. Type the following line, save and quit:</p>
<p><pre class="brush: css; title: ; notranslate">
third-party/cake_1.2.0.5875 -r 5875 https://svn.cakephp.org/repo/trunk/cake/1.2.x.x/
</pre>
<p>Since this is an actual change to the current directory, we should commit it back to the repository:</p>
<pre class="brush: css; title: ; notranslate">
$ svn commit -m &quot;Added externals definition for CakePHP 1.2 rev. 5875&quot;
</pre>
<p>By updating our working copy, the cakephp files will be downloaded to the in the property specified directory:</p>
<pre class="brush: css; title: ; notranslate">
$ svn update
</pre>
<p><!-- adman --></p>
<p>Wow, that&#8217;s nice, isn&#8217;t it! Oh&#8230; and btw, don&#8217;t forget to donate some change to the project!</p>
<p>Let&#8217;s go and make some symlinks and a copy of the &#8216;app&#8217; directory:</p>
<pre class="brush: css; title: ; notranslate">
$ ln -s third-party/cake_1.2.0.5875/.htaccess
$ ln -s third-party/cake_1.2.0.5875/cake
$ ln -s third-party/cake_1.2.0.5875/index.php
# now create your own copy of the app directory
$ cp -r third-party/cake_1.2.0.5875/app .
</pre>
<p>Since we don&#8217;t need the .svn directories from the cakephp svn checkout. We find and delete them:</p>
<pre class="brush: css; title: ; notranslate">
$ find app -type d | grep \.svn | sort -r | xargs rm -rf
</pre>
<p>Finally, add the &#8216;/app&#8217; directory and the simlinks to our own subversion repository</p>
<pre class="brush: css; title: ; notranslate">
$ svn add .htaccess app cake index.php
$ svn commit
</pre>
<p>
That should be it!</p>
<p>Remember, when you want to upgrade your CakePHP version. It should be a matter of (a) editing the externals definition on the myproject directory. And (b) re-linking the symbolic links.</p>
]]></content:encoded>
			<wfw:commentRss>http://nerdnotes.org/2007/12/howto-start-your-cakephp-project-in-subversion/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>&#8216;Compact&#8217; bash prompt</title>
		<link>http://nerdnotes.org/2007/07/compact-bash-prompt/</link>
		<comments>http://nerdnotes.org/2007/07/compact-bash-prompt/#comments</comments>
		<pubDate>Mon, 30 Jul 2007 20:47:25 +0000</pubDate>
		<dc:creator>Bram</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[nerdnotes]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://86</guid>
		<description><![CDATA[Especially when working with cakephp, the following line in your .bash_profile script might come in handy: It will print out the current working directory on the first line and the actual bash prompt on the second line. Making it less likely that your command will wrap lines after the first few typed characters. It changes [...]]]></description>
			<content:encoded><![CDATA[<p>Especially when working with cakephp, the following line in your .bash_profile script might come in handy:</p>
<pre class="brush: css; title: ; notranslate">
HOSTCOLOR=&quot;31m&quot;
PS1=&quot;\u@\[\e[${HOSTCOLOR}\]\h\[\e[0m\]:\w\n\[\e[33m\]\!\[\e[0m\] \$ &quot;
</pre>
<p>It will print out the current working directory on the first line and the actual bash prompt on the second line. Making it less likely that your command will wrap lines after the first few typed characters.<br />
It changes the command prompt from:</p>
<p><img id="image112" src="http://nerdnotes.org/wp-content/uploads/2007/07/cmdline-long.png" alt="command line long" /></p>
<p>&#8230;.into:</p>
<p><img id="image110" src="http://nerdnotes.org/wp-content/uploads/2007/07/cmdline-short.png" alt="command line 'short'" /></p>
<p>The login prompt now shows the following info:</p>
<ul>
<li>username</li>
<li>hostname in red (in my bash script, it will print red for one group of servers and blue for other servers)</li>
<li>current working directory</li>
<li>command history number, ie: use !520 to execute the previous command</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://nerdnotes.org/2007/07/compact-bash-prompt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP radio button example</title>
		<link>http://nerdnotes.org/2007/01/cakephp-radio-button-example/</link>
		<comments>http://nerdnotes.org/2007/01/cakephp-radio-button-example/#comments</comments>
		<pubDate>Fri, 26 Jan 2007 21:06:41 +0000</pubDate>
		<dc:creator>Bram</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[nerdnotes]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://79</guid>
		<description><![CDATA[Thanks Ronnie, for the example! It looks like this useful hint won&#8217;t appear in the cakephp documentation any time soon. I think is&#8217;t &#8220;nerdnoteworthy&#8221;:]]></description>
			<content:encoded><![CDATA[<p><a href="http://nerdnotes.org/wp-content/uploads/2007/01/cakephpradiobuttons.png" class="imagelink" title="cakephp radio buttons" target="_blank"><img src="http://nerdnotes.org/wp-content/uploads/2007/01/cakephpradiobuttons.png" id="image101" alt="cakephp radio buttons.png" /></a><br />
Thanks Ronnie, for the <a href="https://trac.cakephp.org/ticket/818" target="_blank">example</a>! It looks like this useful hint won&#8217;t appear in the cakephp documentation any time soon. I think is&#8217;t &#8220;nerdnoteworthy&#8221;:</p>
<pre class="brush: php; title: ; notranslate">
echo $html-&gt;radio(
	'User/admin',
	array(
		'no' =&gt; 'No',
		'yes' =&gt; 'Yes'),
	null,
	array('value' =&gt; 'no')
);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://nerdnotes.org/2007/01/cakephp-radio-button-example/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>

