New Controller::set() behavior - Changeset 5231

4 views
Skip to first unread message

Felix Geisendörfer

unread,
Nov 14, 2007, 4:03:37 PM11/14/07
to cakeph...@googlegroups.com
Hey folks,

ok, this change has been made a long time ago (6 months ...), but for some reason I just noticed it now (and the impact it had on my app).

If you use Controller->set('a', 'b') you're fine.

If you use Controller->set($data); you might be in trouble.

Since: https://trac.cakephp.org/changeset/5231 underscored variables passed in the set($one) format will be caramelized. This means:

Controller->set(array('my_var' => 'my val'));

Will not set your variable as $my_var in the view, but as $myVar! Not sure why this is the case, but keep it in mind when you use the 1 parameter syntax : ).

HTH,
-- Felix
--------------------------
Blogger: http://www.thinkingphp.org/
Entrepreneur: http://www.posttask.com/ -- currently in private beta, ask me for invite / password
Freelancer: http://www.fg-webdesign.de/

AIM: theundefined87
Skype: TimeFor23
Other IM: felixge.de
Mobile (USA): +1 404 3888693
Mobile (GER): +49 162 9391612
Twitter: http://twitter.com/felixge

Grant Cox

unread,
Nov 14, 2007, 5:46:46 PM11/14/07
to CakePHP Bleeding Edge
Mmmm, caramelized variables :)

You can avoid this by passing anything as the second parameter, so:

$this->set( array('my_var'=>'my val'), false );

will come through to your view as $my_var, not $myVar.


On Nov 15, 7:03 am, Felix Geisendörfer <haimu...@gmail.com> wrote:
> Hey folks,
>
> ok, this change has been made a long time ago (6 months ...), but for
> some reason I just noticed it now (and the impact it had on my app).
>
> If you use Controller->set('a', 'b') you're fine.
>
> If you use Controller->set($data); you might be in trouble.
>

> Since:https://trac.cakephp.org/changeset/5231underscored variables


> passed in the set($one) format will be caramelized. This means:
>
> Controller->set(array('my_var' => 'my val'));
>
> Will not set your variable as $my_var in the view, but as $myVar! Not
> sure why this is the case, but keep it in mind when you use the 1
> parameter syntax : ).
>
> HTH,
> -- Felix
> --------------------------
> Blogger:http://www.thinkingphp.org/

> Entrepreneur:http://www.posttask.com//-- currently in private beta,
> ask me for invite / password/


> Freelancer:http://www.fg-webdesign.de/
>
> AIM: theundefined87
> Skype: TimeFor23

> Other IM: felixge.de <http://felixge.de/>

Felix Geisendörfer

unread,
Nov 15, 2007, 12:25:48 PM11/15/07
to cakeph...@googlegroups.com
Hey,
Mmmm, caramelized variables :)
I should open a ticket to call the function 'caramelize'. Its <Cake>PHP after all, isn't it? : )
You can avoid this by passing anything as the second parameter, so:
True. I just said I didn't expect the new default behavior ; ).

-- Felix
--------------------------
Blogger: http://www.thinkingphp.org/
Entrepreneur: http://www.posttask.com/ -- currently in private beta, ask me for invite / password
Freelancer: http://www.fg-webdesign.de/

AIM: theundefined87
Skype: TimeFor23
Other IM: felixge.de
Mobile (USA): +1 404 3888693
Mobile (GER): +49 162 9391612
Twitter: http://twitter.com/felixge
Reply all
Reply to author
Forward
0 new messages