Controller::set(), as you can see, adds a variable with the supplied
name & value to the $viewVars array which, in turn, is made available
to the View object. However, you're not creating a *local* variable
with the given name & value. For that, you'd need to first asign it to
a variable, then use set() to make it available to the View:
$foo = 'bar';
$this->set('foo', $foo);
If you need to set several vars for the view but need to use them in
the controller, you can do:
$foo = 'foo';
$bar = 'bar';
...
$this->set(compact('foo', 'bar'));
... which will do the same thing.
One other thing you should know about: Cake will screw with your
variable names if you're not careful. If there's an underscore in the
variable name and you use compact(), you have to take an extra measure
or Cake will create a camel-cased variable name (no, I don't
understand why). So, if you do:
$this->set(compact('foo_bar'));
... you'll end up with a $fooBar variable in the View instead of
$foo_bar. To avoid this, do:
$foo_bar = 'whatever';
$this->set(compact('foo_bar'), false);
On Fri, Aug 7, 2009 at 6:03 PM, geste<[email protected]> wrote:
>
> Sometimes I hit myself with a small, embarrassing clue stick
> immediately after posting.
>
> I thought I had tried using $this->viewVars['whatever' ] in my find
> conditions and that it just didn't work.
>
> But I just tried that little test of:
>
> $this->set('menu_link', "/budgets" );
> $this->set('menu_name', $this->viewVars['menu_link']);
>
> and it does seem to work. (menu_name gets set to "/budgets")
>
> So I think I need to go back and rework my find() conditions to try
> $this->viewVars[whatever] again
>
> Any other comments about the validity of using $this->viewVars in
> controller logic welcome.
>
> Jim
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---