<?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; feature</title>
	<atom:link href="http://cakebaker.42dh.com/tags/feature/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakebaker.42dh.com</link>
	<description>baking cakes with CakePHP</description>
	<lastBuildDate>Tue, 20 Dec 2011 15:29:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Magic timestamps with Rails and CakePHP</title>
		<link>http://cakebaker.42dh.com/2009/02/16/magic-timestamps-with-rails-and-cakephp/</link>
		<comments>http://cakebaker.42dh.com/2009/02/16/magic-timestamps-with-rails-and-cakephp/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 16:19:34 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[feature]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=1108</guid>
		<description><![CDATA[Both frameworks provide the feature of automatically setting the creation/modification datetime of a database record. For this feature to work, you have to add datetime columns to your tables which follow some naming conventions. For some reason, CakePHP uses different conventions for this feature than Rails&#8230; In CakePHP, the names of those &#8220;magic&#8221; columns are: [...]]]></description>
			<content:encoded><![CDATA[<p>Both frameworks provide the feature of automatically setting the creation/modification datetime of a database record. For this feature to work, you have to add datetime columns to your tables which follow some naming conventions. For some reason, CakePHP uses different conventions for this feature than Rails&#8230;</p>
<p>In CakePHP, the names of those &#8220;magic&#8221; columns are:</p>
<pre>
<code>created
modified / updated</code>
</pre>
<p>In Rails, on the other hand, the respective column names are:</p>
<pre>
<code>created_at / created_on
updated_at / updated_on</code>
</pre>
<p>Fortunately, the other database-related naming conventions seem to be the same in both frameworks.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2009/02/16/magic-timestamps-with-rails-and-cakephp/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Plugin-specific styles, images, and javascript files</title>
		<link>http://cakebaker.42dh.com/2008/08/04/plugin-specific-styles-images-and-javascript-files/</link>
		<comments>http://cakebaker.42dh.com/2008/08/04/plugin-specific-styles-images-and-javascript-files/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 15:19:09 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[feature]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=650</guid>
		<description><![CDATA[One missing piece for using plugins as mini-applications was the ability to have plugin-specific styles, images and javascript files. You had to put them to the respective folders in your application, or you had to use some hacks. In the meantime this ability has been introduced (I don&#8217;t know when it was added). To make [...]]]></description>
			<content:encoded><![CDATA[<p>One missing piece for using plugins as mini-applications was the ability to have plugin-specific styles, images and javascript files. You had to put them to the respective folders in your application, or you had to use some hacks.</p>
<p>In the meantime this ability has been introduced (I don&#8217;t know when it was added). To make use of it, you have to add a &#8220;vendors&#8221; folder with the subfolders &#8220;css&#8221;, &#8220;img&#8221;, and &#8220;js&#8221; to your plugin:</p>
<pre>
app
  plugins
    myplugin
      vendors
         css
         img
         js
</pre>
<p>Files in those folders can then be accessed like http://example.com/myplugin/img/my_image.jpg.</p>
<p>Unfortunately, HtmlHelper and JavascriptHelper are not (yet?) aware of this new feature. For example, the following code used in a view of your plugin:</p>
<pre>
<code>&lt;?php echo $html-&gt;image('my_image.jpg'); ?&gt;</code>
</pre>
<p>will create this HTML code:</p>
<pre>
<code>&lt;img src="/img/my_image.jpg" alt="" /&gt;</code>
</pre>
<p>As you see, the path points to the &#8220;img&#8221; folder of your application, and not to the &#8220;img&#8221; folder of your plugin. To avoid this, we have to specify the full path to the image:</p>
<pre>
<code>&lt;?php echo $html-&gt;image('/'.$this-&gt;plugin.'/img/my_image.jpg'); ?&gt;
// creates: &lt;img src="/myplugin/img/my_image.jpg" alt="" /&gt;</code>
</pre>
<p>The same also applies when including CSS styles and Javascript files.</p>
<p>Happy plugin baking :)</p>
<p>PS1: A new &#8220;notEmpty&#8221; validation rule has recently been added (&#8220;teknoid&#8221; was faster with an article, so here just a link to his <a href="http://teknoid.wordpress.com/2008/07/31/notempty-validation-rule/">article</a>). </p>
<p>PS2: A <a href="http://www.galileocomputing.de/techtalks/frameworks_cms">CakePHP presentation</a> (in German) by <a href="http://teemow.com">Timo Derstappen</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2008/08/04/plugin-specific-styles-images-and-javascript-files/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>New callback methods for components</title>
		<link>http://cakebaker.42dh.com/2008/06/02/new-callback-methods-for-components/</link>
		<comments>http://cakebaker.42dh.com/2008/06/02/new-callback-methods-for-components/#comments</comments>
		<pubDate>Mon, 02 Jun 2008 14:32:19 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[component]]></category>
		<category><![CDATA[feature]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=608</guid>
		<description><![CDATA[Recently, support for three new component callback methods has been added: beforeRender, beforeRedirect, and shutdown. (Correction: those callbacks have been around for quite a while, see Nate&#8217;s comment, but I noticed them only recently) As its name implies, the beforeRender() callback method is called before the view is rendered, but after the beforeRender() callback method [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, support for three new component callback methods has been added: beforeRender, beforeRedirect, and shutdown. (Correction: those callbacks have been around for quite a while, see Nate&#8217;s comment, but I noticed them only recently)</p>
<p>As its name implies, the <strong>beforeRender()</strong> callback method is called before the view is rendered, but after the beforeRender() callback method of the controller:</p>
<pre>
// in your component
public function beforeRender($controller) {
    // do something
}
</pre>
<p>The <strong>beforeRedirect()</strong> callback is also quite obvious, it gets called before a redirect is performed:</p>
<pre>
// in your component
public function beforeRedirect($controller, $url, $status = null, $exit = true) {
    // do something
}
</pre>
<p>By providing a return value, you can override the values with which the redirect method was originally called. For example:</p>
<pre>
public function beforeRedirect($controller, $url, $status = null, $exit = true) {
    // return '/redirect/target';  // a single value is treated as an URL
    return array('url' =&gt; '/redirect/target', 'status' =&gt; 307);
}
</pre>
<p>The last callback method, <strong>shutdown()</strong>, is called after Controller::render() and before Controller::afterFilter():</p>
<pre>
// in your component
public function shutdown($controller) {
    // do something
}
</pre>
<p>Those callback methods are probably a &#8220;nice to have&#8221; feature, at least I didn&#8217;t miss them up to now.</p>
<p>Anyway, happy baking!</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2008/06/02/new-callback-methods-for-components/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Three new validation rules</title>
		<link>http://cakebaker.42dh.com/2008/05/21/three-new-validation-rules/</link>
		<comments>http://cakebaker.42dh.com/2008/05/21/three-new-validation-rules/#comments</comments>
		<pubDate>Wed, 21 May 2008 17:32:18 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[deprecated]]></category>
		<category><![CDATA[feature]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[validation]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=605</guid>
		<description><![CDATA[Recently, three new validation methods have been added to the core validation class and hence you can use three more validation rules in your models: boolean, inList, and time. boolean is self-explanatory: it validates whether a field contains a boolean value (i.e. 0, 1, &#8220;0&#8243;, &#8220;1&#8243;, false, or true). Example: var $validate = array('is_enabled' =&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, three new validation methods have been added to the core validation class and hence you can use three more validation rules in your models: boolean, inList, and time. </p>
<p><strong>boolean</strong> is self-explanatory: it validates whether a field contains a boolean value (i.e. 0, 1, &#8220;0&#8243;, &#8220;1&#8243;, false, or true). Example:</p>
<pre>
var $validate = array('is_enabled' =&gt; array('rule' =&gt; array('boolean')));
</pre>
<p><strong>inList</strong> ensures that the respective field only contains a value from the defined array. It is case-sensitive, i.e. if you use the rule from the example below, then the value &#8220;Red&#8221; would be invalid.</p>
<pre>
var $validate = array('color' =&gt; array('rule' =&gt; array('inList', array('red', 'green', 'blue'))));
</pre>
<p><strong>time</strong> determines whether a field contains a valid time value. It supports both the 24 hour format (e.g. 08:10:10) and the 12 hour format (e.g. 8:10:10am). The minutes and seconds are optional in both cases.</p>
<pre>
var $validate = array('starttime' =&gt; array('rule' =&gt; array('time')));
</pre>
<p>Another recent change affected View::renderElement(): it has been deprecated in favor of View::element():</p>
<pre>
$this-&gt;renderElement('my_element', array('param1' =&gt; 'a value'));

becomes

$this-&gt;element('my_element', array('param1' =&gt; 'a value'));
</pre>
<p>I don&#8217;t know why View::renderElement() was deprecated and not View::element(), as I think the method name &#8220;renderElement&#8221; is more expressive than &#8220;element&#8221;.</p>
<p>Anyway, happy baking :)</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2008/05/21/three-new-validation-rules/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>New core behavior: Containable</title>
		<link>http://cakebaker.42dh.com/2008/05/18/new-core-behavior-containable/</link>
		<comments>http://cakebaker.42dh.com/2008/05/18/new-core-behavior-containable/#comments</comments>
		<pubDate>Sun, 18 May 2008 16:28:25 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[behavior]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[feature]]></category>
		<category><![CDATA[model]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=604</guid>
		<description><![CDATA[With changeset 6918 a new behavior has been introduced to CakePHP: Containable. It&#8217;s a mix of the original Containable behavior by Felix Geisendörfer (aka the_undefined) and the Bindable behavior by Mariano Iglesias. To use the new behavior, you either have to add it to the $actsAs property of your model: class Post extends AppModel { [...]]]></description>
			<content:encoded><![CDATA[<p>With <a href="https://trac.cakephp.org/changeset/6918">changeset 6918</a> a new behavior has been introduced to CakePHP: Containable. It&#8217;s a mix of the original Containable behavior by <a href="http://debuggable.com">Felix Geisendörfer (aka the_undefined)</a> and the Bindable behavior by <a href="http://cricava.com/blogs/mariano.php">Mariano Iglesias</a>.</p>
<p>To use the new behavior, you either have to add it to the $actsAs property of your model:</p>
<pre>
class Post extends AppModel {
    var $actsAs = array('Containable');
}
</pre>
<p>or you can attach the behavior on the fly with:</p>
<pre>
$this-&gt;Post-&gt;Behaviors-&gt;attach('Containable');
</pre>
<p>Ok, now let&#8217;s have a look at some examples. For the examples I will use the three models Post, Comment, and Tag, with the associations: Post hasMany Comments, Post hasAndBelongsToMany Tags.</p>
<p>If we perform a simple find all statement, then we get back all posts plus all associated records, something like:</p>
<pre>
debug($this-&gt;Post-&gt;find('all'));

[0] =&gt; Array
        (
            [Post] =&gt; Array
                (
                    [id] =&gt; 1
                    [title] =&gt; First article
                    [content] =&gt; aaa
                    [created] =&gt; 2008-05-18 00:00:00
                )
            [Comment] =&gt; Array
                (
                    [0] =&gt; Array
                        (
                            [id] =&gt; 1
                            [post_id] =&gt; 1
                            [author] =&gt; Daniel
                            [email] =&gt; dan@example.com
                            [website] =&gt; http://example.com
                            [comment] =&gt; First comment
                            [created] =&gt; 2008-05-18 00:00:00
                        )
                    [1] =&gt; Array
                        (
                            [id] =&gt; 2
                            [post_id] =&gt; 1
                            [author] =&gt; Sam
                            [email] =&gt; sam@example.net
                            [website] =&gt; http://example.net
                            [comment] =&gt; Second comment
                            [created] =&gt; 2008-05-18 00:00:00
                        )
                )
            [Tag] =&gt; Array
                (
                    [0] =&gt; Array
                        (
                            [id] =&gt; 1
                            [name] =&gt; A
                        )
                    [1] =&gt; Array
                        (
                            [id] =&gt; 2
                            [name] =&gt; B
                        )
                )
        )
</pre>
<p>But often you don&#8217;t want to get all those data, and that&#8217;s when the Containable behavior comes to the rescue. </p>
<p>To get only the posts, you can do the following:</p>
<pre>
$this-&gt;Post-&gt;contain();
debug($this-&gt;Post-&gt;find('all'));

or

debug($this-&gt;Post-&gt;find('all', array('contain' =&gt; false)));

or without the Containable behavior

$this-&gt;Post-&gt;recursive = -1;
debug($this-&gt;Post-&gt;find('all'));
</pre>
<p>With the contain() method resp. the &#8220;contain&#8221; option we specify from which of the associated models we want to get data. If we want to get all posts plus the associated tags (without the comments), we would do it in the following way:</p>
<pre>
$this-&gt;Post-&gt;contain('Tag'); // we could also use an array
debug($this-&gt;Post-&gt;find('all'));

or

debug($this-&gt;Post-&gt;find('all', array('contain' =&gt; 'Tag'))); // we could also use an array

or without the Containable behavior

$this-&gt;Post-&gt;unbindModel(array('hasMany' =&gt; array('Comment')));
debug($this-&gt;Post-&gt;find('all'));
</pre>
<p>As you can see, the code using the Containable behavior is much cleaner than the code without it.</p>
<p>But that&#8217;s not all the Containable behavior can do for you. You can also filter the data of the associated models. If you are interested in the posts and the names of the comment authors, you could write:</p>
<pre>
$this-&gt;Post-&gt;contain('Comment.author');
debug($this-&gt;Post-&gt;find('all'));

or

debug($this-&gt;Post-&gt;find('all', array('contain' =&gt; 'Comment.author')));

[0] =&gt; Array
        (
            [Post] =&gt; Array
                (
                    [id] =&gt; 1
                    [title] =&gt; First article
                    [content] =&gt; aaa
                    [created] =&gt; 2008-05-18 00:00:00
                )
            [Comment] =&gt; Array
                (
                    [0] =&gt; Array
                        (
                            [author] =&gt; Daniel
                            [post_id] =&gt; 1
                        )
                    [1] =&gt; Array
                        (
                            [author] =&gt; Sam
                            [post_id] =&gt; 1
                        )
                )
        )
</pre>
<p>As you can see, the comment arrays only contain the author plus the post_id (which is needed by Cake to map the results).</p>
<p>You can also filter the (comment) data by using a condition:</p>
<pre>
$this-&gt;Post-&gt;contain('Comment.author = "Daniel"');
debug($this-&gt;Post-&gt;find('all'));

or 

debug($this-&gt;Post-&gt;find('all', array('contain' =&gt; 'Comment.author = "Daniel"')));

[0] =&gt; Array
        (
            [Post] =&gt; Array
                (
                    [id] =&gt; 1
                    [title] =&gt; First article
                    [content] =&gt; aaa
                    [created] =&gt; 2008-05-18 00:00:00
                )
            [Comment] =&gt; Array
                (
                    [0] =&gt; Array
                        (
                            [id] =&gt; 1
                            [post_id] =&gt; 1
                            [author] =&gt; Daniel
                            [email] =&gt; dan@example.com
                            [website] =&gt; http://example.com
                            [comment] =&gt; First comment
                            [created] =&gt; 2008-05-18 00:00:00
                        )
                )
        )
</pre>
<p>As you can see from these examples, the Containable behavior is very powerful, and I recommend to have a look at the tests.</p>
<p>Anyway, it&#8217;s very cool to have this behavior in the core :)</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2008/05/18/new-core-behavior-containable/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
		<item>
		<title>Attaching and detaching model behaviors on-the-fly</title>
		<link>http://cakebaker.42dh.com/2008/02/02/attaching-and-detaching-model-behaviors-on-the-fly/</link>
		<comments>http://cakebaker.42dh.com/2008/02/02/attaching-and-detaching-model-behaviors-on-the-fly/#comments</comments>
		<pubDate>Sat, 02 Feb 2008 08:08:02 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[behavior]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[feature]]></category>
		<category><![CDATA[model]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/2008/02/02/attaching-and-detaching-model-behaviors-on-the-fly/</guid>
		<description><![CDATA[A feature recently added to CakePHP is the possibility to attach and detach model behaviors on-the-fly (see changeset 6415). Let&#8217;s have a look at this feature with a simple example. First we create a behavior which outputs a text before a find operation is performed: // app/models/behaviors/example.php class ExampleBehavior extends ModelBehavior { private $text = [...]]]></description>
			<content:encoded><![CDATA[<p>A feature recently added to CakePHP is the possibility to attach and detach model behaviors on-the-fly (see <a href="https://trac.cakephp.org/changeset/6415">changeset 6415</a>). Let&#8217;s have a look at this feature with a simple example. </p>
<p>First we create a behavior which outputs a text before a find operation is performed:</p>
<pre>
// app/models/behaviors/example.php
class ExampleBehavior extends ModelBehavior {
    private $text = 'this is an example text';

    function setUp(&#038;$model, $config) {
        if (isset($config['text'])) {
            $this-&gt;text = $config['text'];
        }
    }

    function beforeFind(&#038;$model, $query) {
        echo $this-&gt;text;

        return true;
    }
}
</pre>
<p>The usual way to use a behavior is to define it with the $actsAs variable in the model. For example, to use the ExampleBehavior with the Post model, we would define it in the following way:</p>
<pre>
// app/models/post.php
class Post extends AppModel {
    var $actsAs = array('Example' =&gt; array('text' =&gt; 'some text'));
}
</pre>
<p>Every time we execute a find method of the Post model, the string &#8220;some text&#8221; is echoed. </p>
<p><del datetime="2008-08-14T15:50:49+00:00">With the new methods Model::attach() and Model::detach()</del> With having a BehaviorCollection (with the methods attach() and detach()) as a property of the model more flexible scenarios are possible (even though I can&#8217;t think of any real use cases at the moment). If we want our Post model to act as Example only temporarily, we could write the following code:</p>
<pre>
// app/models/post.php
class Post extends AppModel {
}

// action in our controller
function index() {
    $this-&gt;Post-&gt;Behaviors-&gt;attach('Example', array('text' =&gt; 'hello world'));
    $this-&gt;set('all_posts', $this-&gt;Post-&gt;find('all'));
    $this-&gt;Post-&gt;Behaviors-&gt;detach('Example');
    $this-&gt;set('first_post', $this-&gt;Post-&gt;findById(1));
}
</pre>
<p>When we perform the find(&#8216;all&#8217;) statement, our Post model acts as Example, i.e. the specified text is echoed, whereas with the findById statement, it no longer acts as Example, and so there is no output. </p>
<p>Happy baking :)</p>
<p>Update (2008-08-14): The example now uses the methods of the BehaviorCollection object, which is a property of the model. Thanks to <a href="http://tumble.kabturek.info/">kabturek</a> for the hint!</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2008/02/02/attaching-and-detaching-model-behaviors-on-the-fly/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>A small change in Controller::redirect()</title>
		<link>http://cakebaker.42dh.com/2007/12/24/a-small-change-in-controllerredirect/</link>
		<comments>http://cakebaker.42dh.com/2007/12/24/a-small-change-in-controllerredirect/#comments</comments>
		<pubDate>Mon, 24 Dec 2007 07:16:15 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[feature]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/12/24/a-small-change-in-controllerredirect/</guid>
		<description><![CDATA[If you wanted to stop the program execution after a redirect you had to use the code shown below up to now: $this-&#62;redirect('/controller/action', null, true); or $this-&#62;redirect('/controller/action'); exit(); Thanks to a recent change of the API of the &#8220;redirect&#8221; method &#8212; the default value for the $exit parameter was changed from &#8220;false&#8221; to &#8220;true&#8221; &#8212; [...]]]></description>
			<content:encoded><![CDATA[<p>If you wanted to stop the program execution after a redirect you had to use the code shown below up to now:</p>
<pre>
$this-&gt;redirect('/controller/action', null, true);

or

$this-&gt;redirect('/controller/action');
exit();
</pre>
<p>Thanks to a recent <a href="https://trac.cakephp.org/changeset/6208">change</a> of the API of the &#8220;redirect&#8221; method &#8212; the default value for the $exit parameter was changed from &#8220;false&#8221; to &#8220;true&#8221; &#8212; you can now simply use:</p>
<pre>
$this-&gt;redirect('/controller/action');
</pre>
<p>As it does an exit() by default, you can no longer encounter a possible security hole I described in <a href="http://cakebaker.42dh.com/2006/08/28/dont-forget-to-exit-after-a-redirect/">Don&#8217;t forget to exit after a redirect</a> (well, theoretically you can still encounter it when setting the $exit parameter explicitly to &#8220;false&#8221;, but that&#8217;s rather unlikely I think).</p>
<p>Merry Christmas to everyone!</p>
<p>PS: From the activity in the repository it looks like the Cake team is baking a Christmas Cake :)</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2007/12/24/a-small-change-in-controllerredirect/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Rendering elements from controllers</title>
		<link>http://cakebaker.42dh.com/2007/12/21/rendering-elements-from-controllers/</link>
		<comments>http://cakebaker.42dh.com/2007/12/21/rendering-elements-from-controllers/#comments</comments>
		<pubDate>Fri, 21 Dec 2007 08:06:41 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[element]]></category>
		<category><![CDATA[feature]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/12/21/rendering-elements-from-controllers/</guid>
		<description><![CDATA[If you work with Ajax you probably encountered situations when it would have been handy if you could render an element directly from the controller. But that was not possible. You had to use a view, and then from there you could render the element with renderElement(). In the meantime this feature has been added [...]]]></description>
			<content:encoded><![CDATA[<p>If you work with Ajax you probably encountered situations when it would have been handy if you could render an element directly from the controller. But that was not possible. You had to use a view, and then from there you could render the element with renderElement().</p>
<p>In the meantime this feature has been added to the development branch (I don&#8217;t know when) as I learned today from a <a href="https://trac.cakephp.org/ticket/3132#comment:4">comment</a> by gwoo.</p>
<p>If you have an element /app/views/elements/example.ctp in your application, then you can render it with the following code snippet from within your controller:</p>
<pre>
$this-&gt;render('/elements/example');
</pre>
<p>In the same way you can also render views which belong to other controllers.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2007/12/21/rendering-elements-from-controllers/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>An alternative way to create arrays</title>
		<link>http://cakebaker.42dh.com/2007/12/17/an-alternative-way-to-create-arrays/</link>
		<comments>http://cakebaker.42dh.com/2007/12/17/an-alternative-way-to-create-arrays/#comments</comments>
		<pubDate>Mon, 17 Dec 2007 08:02:59 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[feature]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/12/17/an-alternative-way-to-create-arrays/</guid>
		<description><![CDATA[As I use more and more mock objects when testing I often have to fake the results of some findAll calls. That means I have to create array structures as shown in the following example: $expectedPosts = array(array('Post' =&#62; array('id' =&#62; 3, 'title' =&#62; 'a title', 'content' =&#62; 'some content')), array('Post' =&#62; array('id' =&#62; 4, [...]]]></description>
			<content:encoded><![CDATA[<p>As I use more and more <a href="http://cakebaker.42dh.com/2007/12/04/testing-with-partial-mock-objects/">mock objects</a> when testing I often have to fake the results of some findAll calls. That means I have to create array structures as shown in the following example:</p>
<pre>
$expectedPosts = array(array('Post' =&gt; array('id' =&gt; 3, 'title' =&gt; 'a title', 'content' =&gt; 'some content')),
			               array('Post' =&gt; array('id' =&gt; 4, 'title' =&gt; 'another title', 'content' =&gt; 'some other content')));
</pre>
<p>The core class <a href="http://api.cakephp.org/1.2/class_set.html">Set</a> provides an alternative way to create arrays using a dot notation. The example from above can be rewritten as:</p>
<pre>
$expectedPosts = array();
$expectedPosts = Set::insert($expectedPosts, '0.Post.id', 3);
$expectedPosts = Set::insert($expectedPosts, '0.Post.title', 'a title');
$expectedPosts = Set::insert($expectedPosts, '0.Post.content', 'some content');
$expectedPosts = Set::insert($expectedPosts, '1.Post.id', 4);
$expectedPosts = Set::insert($expectedPosts, '1.Post.title', 'another title');
$expectedPosts = Set::insert($expectedPosts, '1.Post.content', 'some other content');
</pre>
<p>You can also mix those two approaches:</p>
<pre>
$expectedPosts = array();
$expectedPosts = Set::insert($expectedPosts, '0.Post', array('id' =&gt; 3, 'title' =&gt; 'a title', 'content' =&gt; 'some content'));
$expectedPosts = Set::insert($expectedPosts, '1.Post', array('id' =&gt; 4, 'title' =&gt; 'another title', 'content' =&gt; 'some other content'));
</pre>
<p>It is quite handy, especially if you have to create more complex array structures. </p>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2007/12/17/an-alternative-way-to-create-arrays/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Slugify strings</title>
		<link>http://cakebaker.42dh.com/2007/10/07/slugify-strings/</link>
		<comments>http://cakebaker.42dh.com/2007/10/07/slugify-strings/#comments</comments>
		<pubDate>Sun, 07 Oct 2007 09:07:58 +0000</pubDate>
		<dc:creator>cakebaker</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[feature]]></category>

		<guid isPermaLink="false">http://cakebaker.42dh.com/2007/10/07/slugify-strings/</guid>
		<description><![CDATA[In a recent changeset a nice, little function has been introduced: Inflector::slug(). Such a function is used for example in blogs to create urls from titles. Its usage is simple: echo Inflector::slug('This is a test'); // outputs: This_is_a_test echo Inflector::slug('This is a test', '-'); // outputs: This-is-a-test You have to be careful with this function [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent changeset a nice, little function has been introduced: Inflector::slug(). Such a function is used for example in blogs to create urls from titles. </p>
<p>Its usage is simple:</p>
<pre>
echo Inflector::slug('This is a test');
// outputs: This_is_a_test

echo Inflector::slug('This is a test', '-');
// outputs: This-is-a-test
</pre>
<p>You have to be careful with this function if you use it for example with german umlauts, as you may get an unexpected result:</p>
<pre>
echo Inflector::slug('Es sind Kühe auf der Wiese');
// outputs: Es_sind_K_he_auf_der_Wiese
</pre>
]]></content:encoded>
			<wfw:commentRss>http://cakebaker.42dh.com/2007/10/07/slugify-strings/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

