Tuesday, July 6, 2010

Re: CakePHP 1.3 helper and variable name collision.

Is there any way to avoid a conflict if I want to define a variable
named $artist? The problem in the previous code is that $this->Artist
is overwritten by the value of $artist within the loop. This is doubly
frustrating as the case of the variables is different (Artist versus
artist) which PHP is supposed to respect.

On Jul 6, 8:22 pm, Miles J <mileswjohn...@gmail.com> wrote:
> In 1.3 it supports both $artist and $this->Artist.
>
> On Jul 6, 4:53 pm, aleph1 <cubeythero...@gmail.com> wrote:
>
>
>
> > I thought in CakePHP 1.3 the issue with helpers and variables
> > colliding had been resolved. However, in the below view code the
> > gettype function outside of the loop references the ArtistHelper
> > correctly (returns "object"), and inside refers to the $artist
> > variable (returns "array").
>
> > <?php
> > echo gettype($this->Artist);
> > foreach($artists as $artist) {
> >         echo gettype($this->Artist);
> >         $url = $this->Artist->url($artist['Artist']['slug']);}
>
> > ?>
>
> > I would rather avoid a different name for the variable, as "artist" is
> > the most descriptive name. Has this not been resolved, or am I doing
> > something wrong?

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate