On Apr 10, 11:16 am, qwanta <[email protected]> wrote:
> I am setting a variable value that in app_controller beforeFilter, and
> I would like to access it in all child controllers beforeFilter
> function.
>
> class AppController extends Controller {
> var $components = array('Auth');
> var $uses = array('User');
>
> $auth_id = $this->Auth->user('id');
> if ( $auth_id ) {
> $auth_role = $this->User->getRole($auth_id);
> }
>
> }
>
> class XController extends AppController {
> (...)
> function beforeFIlter() {
> parent::beforeFilter();
> if ($auth_role == "calibrator") {
> (...)
> }
> }
>
> }
>
> When I call a method in XController. I get an $auth_role not defined
> error. Is there a way to pass the variable value to the child
> controller?
> Thanks
one way could be ~
set your $auth_role as a property of AppController:
class AppController {
public $auth_role;
function beforeFIlter() {
$this->auth_role = whatever();
}
}
class XController extends AppController {
function anyFunction()
if ($this->auth_role = blah) { }
}
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---