All that being said, I *could* have passed the values to the widget - which is basically a view - but this was already a relatively poorly designed 3rd party module, and I just wanted to move forward. (This is also a very useful module that provides a lot of functionality that I'd prefer not to write myself, so I'm making modifications to get it to work a little better.) This meant finding some other way to gain access to some variables that had been set in the config file for the module. This is done like so:
// other Yii confi things go here, like components, import, etc
'import' => array(
...
),
'components' => array(
...
),
// and here is where the module goes
'modules' => array(
'moduleName' => array(
'moduleVar1' => 'value',
'moduleVar2' => 'otherValue',
'moduleArray' => array(
'key' => 'val'
),
),
// More things happen here
In this example, I wanted to do something like find out what the value of "moduleVar1" was. There's a way to get at these sorts of things by basically starting from the top (the application level) and working your way down by using Yii::app(). Here, for example, is how you can see which modules are loaded across the entire application:
print_r(Yii::app()->getModules());
To get a specific module, you do this:
Yii::app()->getModule('moduleName');
To get the value for a variable from that module, you'd do this:
Yii::app()->getModule('moduleName')->moduleVar1
And actually, I had an array of values called 'config' like 'moduleArray' above, in which case I needed to get the value of a key of that array, like so:
Yii::app()->getModule('moduleName')->moduleArray['key']
Hope this helps someone.
That's funy :D
ReplyDeleteAfter finding your blog via Google and reading the article, I had the impression that, from how the text is writte and how well it is explained, the author must be a woman.
After reaching the bottom and following the link to your G+ profile, it was so great to see that the feeling of the article was right.
Asides of that fact, it was also a great help! Thanks a lot!
nice post..need more posts on yii. :)
ReplyDeletewhat about components from a module ?
ReplyDelete