<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Don&#8217;t (ab)use the AppHelper to extend the core helpers</title>
	<atom:link href="http://cakebaker.42dh.com/2008/10/18/dont-abuse-the-apphelper-to-extend-the-core-helpers/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakebaker.42dh.com/2008/10/18/dont-abuse-the-apphelper-to-extend-the-core-helpers/</link>
	<description>baking cakes with CakePHP</description>
	<lastBuildDate>Tue, 16 Mar 2010 17:17:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2008/10/18/dont-abuse-the-apphelper-to-extend-the-core-helpers/comment-page-1/#comment-113183</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Fri, 21 Nov 2008 14:23:57 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=900#comment-113183</guid>
		<description>@Abhimanyu: Well, it is one possible way, and not necessarily the best. It&#039;s possible there are better solutions, depending on your requirements. 

For example, the approach described by Derick in a earlier &lt;a href=&quot;http://cakebaker.42dh.com/2008/10/18/dont-abuse-the-apphelper-to-extend-the-core-helpers/#comment-110652&quot; rel=&quot;nofollow&quot;&gt;comment&lt;/a&gt; is in my opinion better than the idea I described in the linked article, though it comes with the &quot;disadvantage&quot; that you have to use a different name to access the helper. If it&#039;s ok for you to use, for example, $appForm instead of $form throughout your application, then go for it!</description>
		<content:encoded><![CDATA[<p>@Abhimanyu: Well, it is one possible way, and not necessarily the best. It&#8217;s possible there are better solutions, depending on your requirements. </p>
<p>For example, the approach described by Derick in a earlier <a href="http://cakebaker.42dh.com/2008/10/18/dont-abuse-the-apphelper-to-extend-the-core-helpers/#comment-110652" rel="nofollow">comment</a> is in my opinion better than the idea I described in the linked article, though it comes with the &#8220;disadvantage&#8221; that you have to use a different name to access the helper. If it&#8217;s ok for you to use, for example, $appForm instead of $form throughout your application, then go for it!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abhimanyu Grover</title>
		<link>http://cakebaker.42dh.com/2008/10/18/dont-abuse-the-apphelper-to-extend-the-core-helpers/comment-page-1/#comment-113078</link>
		<dc:creator>Abhimanyu Grover</dc:creator>
		<pubDate>Thu, 20 Nov 2008 07:20:28 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=900#comment-113078</guid>
		<description>@Daniel I finally had a chance to review your idea:
http://cakebaker.42dh.com/2008/11/07/an-idea-for-hacking-core-helpers/

I&#039;m still not convinced if its the best way available.</description>
		<content:encoded><![CDATA[<p>@Daniel I finally had a chance to review your idea:<br />
<a href="http://cakebaker.42dh.com/2008/11/07/an-idea-for-hacking-core-helpers/" rel="nofollow">http://cakebaker.42dh.com/2008/11/07/an-idea-for-hacking-core-helpers/</a></p>
<p>I&#8217;m still not convinced if its the best way available.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2008/10/18/dont-abuse-the-apphelper-to-extend-the-core-helpers/comment-page-1/#comment-112179</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Fri, 07 Nov 2008 16:27:53 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=900#comment-112179</guid>
		<description>@John: See my latest article: &lt;a href=&quot;http://cakebaker.42dh.com/2008/11/07/an-idea-for-hacking-core-helpers/&quot; rel=&quot;nofollow&quot;&gt;An idea for hacking core helpers&lt;/a&gt;.

Hope it helps!</description>
		<content:encoded><![CDATA[<p>@John: See my latest article: <a href="http://cakebaker.42dh.com/2008/11/07/an-idea-for-hacking-core-helpers/" rel="nofollow">An idea for hacking core helpers</a>.</p>
<p>Hope it helps!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://cakebaker.42dh.com/2008/10/18/dont-abuse-the-apphelper-to-extend-the-core-helpers/comment-page-1/#comment-112150</link>
		<dc:creator>John</dc:creator>
		<pubDate>Fri, 07 Nov 2008 09:42:45 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=900#comment-112150</guid>
		<description>@cakebaker

Hi - thanks - I really wouldn&#039;t have thought of that idea. 

I&#039;m going to go away and do a bit of experimenting - I&#039;ll try and post something back if / when I get a nice simple solution.

Over the last few days I&#039;ve left the $link-&gt; issue on hold, but in terms of the other things having a checkbox multiple I&#039;ve just  been using custom bake files e.g.

&lt;code&gt;
if(!empty($associations[&#039;hasAndBelongsToMany&#039;])) {
				foreach ($associations[&#039;hasAndBelongsToMany&#039;] as $assocName =&gt; $assocData) {
					echo &quot;\t\techo \$form-&gt;input(&#039;{$assocName}&#039;, array(&#039;multiple&#039; =&gt; &#039;checkbox&#039;));\n&quot;;
				}
			}
&lt;/code&gt;

 - not really as elegant but as long you take your bake files with you from project to project It&#039;ll do - but at work were putting a lot of time building our new system on top of cake so not really a problem !

Cheers</description>
		<content:encoded><![CDATA[<p>@cakebaker</p>
<p>Hi &#8211; thanks &#8211; I really wouldn&#8217;t have thought of that idea. </p>
<p>I&#8217;m going to go away and do a bit of experimenting &#8211; I&#8217;ll try and post something back if / when I get a nice simple solution.</p>
<p>Over the last few days I&#8217;ve left the $link-&gt; issue on hold, but in terms of the other things having a checkbox multiple I&#8217;ve just  been using custom bake files e.g.</p>
<pre><code>if(!empty($associations['hasAndBelongsToMany'])) {
				foreach ($associations['hasAndBelongsToMany'] as $assocName =&gt; $assocData) {
					echo "\t\techo \$form-&gt;input('{$assocName}', array('multiple' =&gt; 'checkbox'));\n";
				}
			}</code></pre>
<p> &#8211; not really as elegant but as long you take your bake files with you from project to project It&#8217;ll do &#8211; but at work were putting a lot of time building our new system on top of cake so not really a problem !</p>
<p>Cheers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: An idea for hacking core helpers - cakebaker</title>
		<link>http://cakebaker.42dh.com/2008/10/18/dont-abuse-the-apphelper-to-extend-the-core-helpers/comment-page-1/#comment-112148</link>
		<dc:creator>An idea for hacking core helpers - cakebaker</dc:creator>
		<pubDate>Fri, 07 Nov 2008 09:14:55 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=900#comment-112148</guid>
		<description>[...] a recent comment by John I got asked whether there is a way to override a method of a core helper like [...]</description>
		<content:encoded><![CDATA[<p>[...] a recent comment by John I got asked whether there is a way to override a method of a core helper like [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2008/10/18/dont-abuse-the-apphelper-to-extend-the-core-helpers/comment-page-1/#comment-112084</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Thu, 06 Nov 2008 16:46:49 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=900#comment-112084</guid>
		<description>@John: Thanks for your comment!

Well, an idea to preserve the $form-&gt;xy() scheme in the view is to create a custom view class (i.e. a class which extends View) and to override the _loadHelpers() method. In this method you then replace the instance of the FormHelper with an instance of your custom helper (which extends the FormHelper). 

The code might look like:
&lt;pre&gt;
&lt;code&gt;
class ExampleView extends View {
    public function &amp;_loadHelpers(&amp;$loaded, $helpers, $parent = null) {
        $loaded = parent::_loadHelpers($loaded, $helpers, $parent);
		
        if (isset($loaded[&#039;Html&#039;])) {
            App::import(&#039;Helper&#039;, &#039;Test&#039;);
            $loaded[&#039;Html&#039;] = new TestHelper();
        }
		
        return $loaded;
    }
}
&lt;/code&gt;
&lt;/pre&gt;
You probably have to copy some code from View::_loadHelpers() to make it work to 100%.

Hope that helps!</description>
		<content:encoded><![CDATA[<p>@John: Thanks for your comment!</p>
<p>Well, an idea to preserve the $form-&gt;xy() scheme in the view is to create a custom view class (i.e. a class which extends View) and to override the _loadHelpers() method. In this method you then replace the instance of the FormHelper with an instance of your custom helper (which extends the FormHelper). </p>
<p>The code might look like:</p>
<pre>
<pre><code>class ExampleView extends View {
    public function &amp;_loadHelpers(&amp;$loaded, $helpers, $parent = null) {
        $loaded = parent::_loadHelpers($loaded, $helpers, $parent);
		
        if (isset($loaded['Html'])) {
            App::import('Helper', 'Test');
            $loaded['Html'] = new TestHelper();
        }
		
        return $loaded;
    }
}</code></pre>
</pre>
<p>You probably have to copy some code from View::_loadHelpers() to make it work to 100%.</p>
<p>Hope that helps!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://cakebaker.42dh.com/2008/10/18/dont-abuse-the-apphelper-to-extend-the-core-helpers/comment-page-1/#comment-111995</link>
		<dc:creator>John</dc:creator>
		<pubDate>Wed, 05 Nov 2008 09:45:41 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=900#comment-111995</guid>
		<description>@Rafael - btw forgot to say thanks for showing how you can put your own $map array in AppHelper.

Cheers</description>
		<content:encoded><![CDATA[<p>@Rafael &#8211; btw forgot to say thanks for showing how you can put your own $map array in AppHelper.</p>
<p>Cheers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://cakebaker.42dh.com/2008/10/18/dont-abuse-the-apphelper-to-extend-the-core-helpers/comment-page-1/#comment-111961</link>
		<dc:creator>John</dc:creator>
		<pubDate>Tue, 04 Nov 2008 20:31:59 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=900#comment-111961</guid>
		<description>Hi Guys

I&#039;ve been reading this post and all the comments with a great deal of interest, as you&#039;ve all seem to have put a great deal of thought into this.

For my current project I&#039;m really getting to start from bare bones and as such am trying to take the opportunity to make something as perfect as possible, and have have manged to map out exactly what I want to do - so anyway this afternoon I get to the next step and something I assumed would be pretty straight forward turns out to be a lot more complex than I imagined so I&#039;m looking for a bit of advice / clarification and I would really appreciate any thoughts or pointers.

What I was seeking to do was to overwrite some of the core helper methods, but I don&#039;t want to alter any core files, or copy the core helper over to app/helpers and modify it, as suggested by Andreas in the 1st comment - due to the sync problem. Now obviously I could either extend one of the core helpers or create a brand new helper to use - which both seem valid solutions.

BUT I don&#039;t want to do it this way because I really don&#039;t want to have to (for instance) replace $form-&gt;input(&#039;somefield&#039;) with say $myform-&gt;input(&#039;somefield&#039;) - I know that seems picky but it as you move between projects it is another thing to change isn&#039;t it? For my current set of projects I&#039;m using a custom bake templates, so it would be very easy to update those to generate everything with $myform-&gt; or $myhtml-&gt; but thats not always the case. So do you think this is possible or I am I just barking up the wrong tree?

By way of actual examples two of the things I want to do are as follows:

1. Override the default $html-&gt;link method to and connect it to Auth - so for example somebody using an application would not see links to actions they did not have the permissions to actually carry out (avoiding somebody clicking a link and then being told they don&#039;t have permission). This isn&#039;t really hard to do, but I was thinking it would make a good shortcut / safety net if I could apply this checking to any link without having to change any exiting code in the views.

2. I don&#039;t want multiple selects - I just want checkboxes - is there some way I can make this the default behaviour (without editing views or core files)?

Cheers John.</description>
		<content:encoded><![CDATA[<p>Hi Guys</p>
<p>I&#8217;ve been reading this post and all the comments with a great deal of interest, as you&#8217;ve all seem to have put a great deal of thought into this.</p>
<p>For my current project I&#8217;m really getting to start from bare bones and as such am trying to take the opportunity to make something as perfect as possible, and have have manged to map out exactly what I want to do &#8211; so anyway this afternoon I get to the next step and something I assumed would be pretty straight forward turns out to be a lot more complex than I imagined so I&#8217;m looking for a bit of advice / clarification and I would really appreciate any thoughts or pointers.</p>
<p>What I was seeking to do was to overwrite some of the core helper methods, but I don&#8217;t want to alter any core files, or copy the core helper over to app/helpers and modify it, as suggested by Andreas in the 1st comment &#8211; due to the sync problem. Now obviously I could either extend one of the core helpers or create a brand new helper to use &#8211; which both seem valid solutions.</p>
<p>BUT I don&#8217;t want to do it this way because I really don&#8217;t want to have to (for instance) replace $form-&gt;input(&#8217;somefield&#8217;) with say $myform-&gt;input(&#8217;somefield&#8217;) &#8211; I know that seems picky but it as you move between projects it is another thing to change isn&#8217;t it? For my current set of projects I&#8217;m using a custom bake templates, so it would be very easy to update those to generate everything with $myform-&gt; or $myhtml-&gt; but thats not always the case. So do you think this is possible or I am I just barking up the wrong tree?</p>
<p>By way of actual examples two of the things I want to do are as follows:</p>
<p>1. Override the default $html-&gt;link method to and connect it to Auth &#8211; so for example somebody using an application would not see links to actions they did not have the permissions to actually carry out (avoiding somebody clicking a link and then being told they don&#8217;t have permission). This isn&#8217;t really hard to do, but I was thinking it would make a good shortcut / safety net if I could apply this checking to any link without having to change any exiting code in the views.</p>
<p>2. I don&#8217;t want multiple selects &#8211; I just want checkboxes &#8211; is there some way I can make this the default behaviour (without editing views or core files)?</p>
<p>Cheers John.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2008/10/18/dont-abuse-the-apphelper-to-extend-the-core-helpers/comment-page-1/#comment-111828</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Sat, 01 Nov 2008 16:15:40 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=900#comment-111828</guid>
		<description>@Rafael: Sorry, I misunderstood your comment. 

The concept makes sense to me, and it is the reason why there is the concept of interfaces. If you program against interfaces, it no longer matters what implementation you use. 

Of course, it doesn&#039;t make sense to define an interface for every framework class, as not every class has to be replaceable. To take your example, it probably doesn&#039;t make much sense to have a Set interface, as the current Set class is a utility class. On the other hand it could be useful to have a Router interface, so you could implement your own routing strategy. 

Hope that answers your question :)</description>
		<content:encoded><![CDATA[<p>@Rafael: Sorry, I misunderstood your comment. </p>
<p>The concept makes sense to me, and it is the reason why there is the concept of interfaces. If you program against interfaces, it no longer matters what implementation you use. </p>
<p>Of course, it doesn&#8217;t make sense to define an interface for every framework class, as not every class has to be replaceable. To take your example, it probably doesn&#8217;t make much sense to have a Set interface, as the current Set class is a utility class. On the other hand it could be useful to have a Router interface, so you could implement your own routing strategy. </p>
<p>Hope that answers your question :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rafaelbandeira3</title>
		<link>http://cakebaker.42dh.com/2008/10/18/dont-abuse-the-apphelper-to-extend-the-core-helpers/comment-page-1/#comment-111764</link>
		<dc:creator>rafaelbandeira3</dc:creator>
		<pubDate>Fri, 31 Oct 2008 20:31:58 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=900#comment-111764</guid>
		<description>@cakebaker: Naah... I was actually asking about what do you think of the concept behind the implementation ... The concept of having overridable core classes. i.e. Making cake load my own Set class, or making it load my own Router class instead of the core one.</description>
		<content:encoded><![CDATA[<p>@cakebaker: Naah&#8230; I was actually asking about what do you think of the concept behind the implementation &#8230; The concept of having overridable core classes. i.e. Making cake load my own Set class, or making it load my own Router class instead of the core one.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
