开发者

Where to set module specific global variables and how

开发者 https://www.devze.com 2023-04-01 19:18 出处:网络
I\'m building a somewhat large application using kohana 3.1. I\'m trying to set module-wide variables, like definitions. It will be some arrays with key => values.

I'm building a somewhat large application using kohana 3.1. I'm trying to set module-wide variables, like definitions. It will be some arrays with key => values.

To give an example, if it was a user module I would like to set the avail开发者_开发技巧able profiles like

$profiles = array(
  'user' => array('desc'=>'common user','access'=>'1'),
  'jonhdoe' => array('desc'=>'not logged user','access'=>0)
);

and use the $profiles all over my module but not on the outside. Should I set it in init.php? If so, how?


Use protected properties in your module class.

protected profiles = array();

somewhere in the module:

$this->profiles = array(
  'user' => array('desc'=>'common user','access'=>'1'),
  'jonhdoe' => array('desc'=>'not logged user','access'=>0)
);

And you can access this array ONLY from module class or its child-classes.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号