php - Can I use a global variable in my controller -



php - Can I use a global variable in my controller -

hello new phalcon, having problem global variables in controller. have controller global variable $mobs , it.

class controllerbase extends controller { public $mobs; public function initialize() { $user = $this -> session -> get("uid"); $user = users::findfirstbyu_id($user); if ($user != null) { if ($user -> f_id != null) { $mobs = mob::find(array("f_id=$user->f_id", "order" => "m_id")); } } } } ?>

according understanding can set , phone call action eg.

public function mobsaction() { foreach ($mobs $mob) { echo $mob->m_displayname; } }

but gives me undefined variable: mobs error

i wondering if possible utilize variable this, or if should have initialise code in each action.

im guessing trying set class variable $mobs in initialize function , trying iterate through them in class function mobsaction, access class variable mobs youll need utilize $this->mobs instead of $mobs, this:

class controllerbase extends controller { public $mobs; public function initialize() { $user = $this -> session -> get("uid"); $user = users::findfirstbyu_id($user); if ($user != null) { if ($user -> f_id != null) { $this->mobs = mob::find(array("f_id=$user->f_id", "order" => "m_id")); } } } public function mobsaction() { foreach ($this->mobs $mob) { echo $mob->m_displayname; } } }

php phalcon

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -