2

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

1 Answer 1

2

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?

Sign up to request clarification or add additional context in comments.

5 Comments

In Yii ideology Module - is an independent program module which has views, controllers, etc. And I want to create the site with few different modules. Each would do their work and do not interact with each other, only the main controller Site must to call each module.
Why do you need to call them from the main controller? Just curious as there could be a different way of solving your problem.
As I explain above I want to build multiprogram application and each module must be a independent program. Each module will do their work and DO NOT interact with each other. How explain you this - I don't know.
OK yes, that's a good practice, try and keep things as modular as time / business allows. But I don't understand why the main controller has to call it. This is something that could possibly be solved by using better URL rules? Unless this is something very specific, in which case your module could be better constructed to allow easier outside access from the main site.
Yes, I think you'r right and I will try to build more correctless URL rules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.