Re: Simple question about $this->set
That's exactly what I ended up doing actually :) On 9/13/06, John Zimmerman <[EMAIL PROTECTED]> wrote: > Depending on your situation it might make sense to make the variable in > question a class variable of your controller. > > Your reusable methods could then check and set the variable as necessary. > Then before your view is rendered (either before you action returns or in a > beforeRender method) you would use the $this->set() method to transfer that > class variable to the view. > > This way you can output debug info all you want and you wouldn't be > modifiying the _viewVars array in your controller directly. > > > On 9/11/06, Bert Van den Brande <[EMAIL PROTECTED]> wrote: > > > > Ok tnx for the explanation :) > > > > Reason I searched for that function was that I had split some > > controller logic into a couple of reusable methods, and at a certain > > point I needed to now the decision of method X inside method Y. > > > > Of course there were plenty other solutions, but looking for a way to > > retrieve the var I had set in method X was my first intention ... > > > > On 9/11/06, nate <[EMAIL PROTECTED]> wrote: > > > > > > Controller::_viewVars is treated as a protected object property. > > > Accessing proctected properties within a class or child of the class is > > > perfectly legal, and I'm not a big fan of adding extra pointless > > > getters and setters. The only reason there's a set( ) method for it is > > > because it provides actual value over and above simply assigning > > > key/value pairs to an associative array. > > > > > > > > > > > > > > > > > > > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Simple question about $this->set
Depending on your situation it might make sense to make the variable in question a class variable of your controller.Your reusable methods could then check and set the variable as necessary. Then before your view is rendered (either before you action returns or in a beforeRender method) you would use the $this->set() method to transfer that class variable to the view. This way you can output debug info all you want and you wouldn't be modifiying the _viewVars array in your controller directly.On 9/11/06, Bert Van den Brande <[EMAIL PROTECTED]> wrote:Ok tnx for the explanation :) Reason I searched for that function was that I had split somecontroller logic into a couple of reusable methods, and at a certainpoint I needed to now the decision of method X inside method Y.Of course there were plenty other solutions, but looking for a way to retrieve the var I had set in method X was my first intention ...On 9/11/06, nate <[EMAIL PROTECTED]> wrote:>> Controller::_viewVars is treated as a protected object property. > Accessing proctected properties within a class or child of the class is> perfectly legal, and I'm not a big fan of adding extra pointless> getters and setters. The only reason there's a set( ) method for it is > because it provides actual value over and above simply assigning> key/value pairs to an associative array.>>> >> --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Simple question about $this->set
Ok tnx for the explanation :) Reason I searched for that function was that I had split some controller logic into a couple of reusable methods, and at a certain point I needed to now the decision of method X inside method Y. Of course there were plenty other solutions, but looking for a way to retrieve the var I had set in method X was my first intention ... On 9/11/06, nate <[EMAIL PROTECTED]> wrote: > > Controller::_viewVars is treated as a protected object property. > Accessing proctected properties within a class or child of the class is > perfectly legal, and I'm not a big fan of adding extra pointless > getters and setters. The only reason there's a set( ) method for it is > because it provides actual value over and above simply assigning > key/value pairs to an associative array. > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Simple question about $this->set
Controller::_viewVars is treated as a protected object property. Accessing proctected properties within a class or child of the class is perfectly legal, and I'm not a big fan of adding extra pointless getters and setters. The only reason there's a set( ) method for it is because it provides actual value over and above simply assigning key/value pairs to an associative array. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Simple question about $this->set
Bert,Logical reason is it is not awkward but correct to use the view var that was set in the controller, they are not even variables until the view "gets" them. If you need to check that your code set them, then the logical place to check is in the var itself, or like I said, since they are output variables check that the variables have been set for the view in the view. Another suggestion create __checkVars($viewVariable); in your controller.Something like this: function __checkVar($viewVariable) { if(in_array($viewVariable, $this->_viewVars)){ // add your code } else { // do something else } }And use it to check your variables.-- /*** @author Larry E. Masters* @var string $userName * @param string $realName* @returns string aka PhpNut* @access public*/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Simple question about $this->set
But why provide an 'awkward' alternative to retrieve a template var you set on a controller , but not a simple get('xxx') function ? I must admit I also searched for this function instinctively a few times ... You're probably gonna smack me with a very logical reason now ey ;) On 9/11/06, nate <[EMAIL PROTECTED]> wrote: > > Eeeh, it's too early in the morning... > > Yeah, my mistake, Nut is correct on this one. You can access any view > vars you set as $this->_viewVars[$varName] > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Simple question about $this->set
Eeeh, it's too early in the morning... Yeah, my mistake, Nut is correct on this one. You can access any view vars you set as $this->_viewVars[$varName] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Simple question about $this->set
On 9/11/06, nate <[EMAIL PROTECTED]> wrote: Okay fine ;-)It's on my to-do list for Cake 1.2.This is not on any todo list, this will not be added. If you need to debug a var that is set for the view, do it in the view where the code should be tested anyway since it is view output, or debug() like Felix mentioned. -- /*** @author Larry E. Masters* @var string $userName* @param string $realName* @returns string aka PhpNut* @access public*/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Simple question about $this->set
Okay fine ;-) It's on my to-do list for Cake 1.2. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Simple question about $this->set
You can do debug($this->_viewVars); I think. -- http://www.thinkingphp.org http://www.fg-webdesign.de Mark Somerville schrieb: NickCarlson wrote: If I do the following in my controller: $this->set('myVar', 2006); How would I access the value of myVar from within my controller? For example, for debugging purposes, I just want to write the following code within my controller, echo $myVar; It is very annoying that you can't do this. Mark --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Simple question about $this->set
NickCarlson wrote: > If I do the following in my controller: > > $this->set('myVar', 2006); > > How would I access the value of myVar from within my controller? > > For example, for debugging purposes, I just want to write the following > code within my controller, > > echo $myVar; It is very annoying that you can't do this. Mark --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Simple question about $this->set
Use the standard way of setting a variable in a PHP Class, if you want to say, set a variable in one method of a class and retrieve it in another. Class SomethingController extends AppController{ function a(){ $this->myVar = "whee"; $this->b(); } function b(){ echo $this->myVar; } } as nate said, $this->set is used for transferring data from the Controller side of things to the View. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Re: Simple question about $this->set
The simple answer is you don't. Set()'ing a variable in the controller doesn't give you access to it in other parts of the controller, but it will show up as $myVar in the view. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---
Simple question about $this->set
If I do the following in my controller: $this->set('myVar', 2006); How would I access the value of myVar from within my controller? For example, for debugging purposes, I just want to write the following code within my controller, echo $myVar; Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~--~~~~--~~--~--~---