I have the code:
$getCookieData = $this->Cookie->read('data');
$getUser = $this->User->find('first', array('conditions' => array('User.username' => $getCookieData['username'])));
Basically I’m using this in a lot of locations to get the users information and either show it, compare it, etc. I was just wondering if there was a more efficient way for me to use the variable all around my site, instead of repeating myself a lot.
You can wrap that in a function:
And call it like
$this->getUSer(). You should put that in class in context of your current value of$thiseg in class where these functions are present.You can also make it
static(egpublic static function getUSer(){...}) in which case you would be able to call it directly usingclassName::getUSer()syntax.