Brian, Many thanks. I got over a bit of a hump on this on Friday with your help. I do of course have another n00b follow up question :)
I am using the authake plug-in for group-based authorization (this nice plug-in has been taken over by Marco Sbragi and is on CakeForge: http://cakeforge.org/projects/authake2/ I has a number of functions such as getLogin() and isPermitted() that seem to work in views. For example, I can user getLogin() to display user ID on the menu page with echo $authak3->getLogin() However, if I try to access the same function in my menus_controller.php with: $testuser = $authak3->getLogin(); I then get a completely empty page/view. I am trying to determine if there is some sort of a general rule about scope of functions between controller and view that makes the whole thing bomb if I reference it from controller. One thing I am guessing is relevant is that Authake is referenced in the app_controller.php in a BeforeFilter() like so: $this->Authake->beforeFilter($this); and all links/controllers are checked against Authake right from the start. The trick is that I want to check all possible menu links for access right *before* I add the link to viewVars->Menu for the view to render. I could access this authake3->isPermitted($menulink) in the view, but then I would wind up adding a pretty fair amount of logic like menu table queries to the view. I'm trying to make as much of that work in the controller as I can. So any, broad clue about this appreciated. My question was starting to get somewhat Authake-specific, but I think I am probably missing something very general, very basic. Jim On Aug 7, 6:49 pm, brian <[email protected]> wrote: > 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 -~----------~----~----~----~------~----~------~--~---
