Reputation: 25
Trying to use modules in Yii and want to get access from main controller (SiteController) for module's methods. Create module with Gii, module name is Car. Trying get access to method search in RequestController, module Car.
echo Yii::app()->Car->Request->search();
And Yii talks me
Property "CWebApplication.carhire" is not defined.
Does anybody knows how to get access to module's methods from another controllers? Thanks
Upvotes: 2
Views: 3632
Reputation: 3242
Your modules don't get put into the application scope. That is components
that can be accessed via Yii::app()->
modules however are accessed via Yii::app()->getModule($moduleName)->
.
This doesn't really help running an action on a controller though. It's difficult to get access too without entirely breaking the point of abstracting the module.
bool.dev's answer Here is the best methods i've seen if you really need too.
But the problem your having is likely pointing to an underlying problem with the structure of your site. If you need access to a module controller function somewhere else in your app, maybe it shouldn't be in the module?
Upvotes: 2