My situation:
I have an extension in vendor, installed by composer. I want to use model from this extension in my controller:
extension-model:
namespace ext\products\models
use ext\products\Module
... rules() ...
['name', 'match', 'pattern' => Module::getInstance()->pattern],
...
in my controller:
use ext\products\model\Product;
$product = new Product();
// some code to fill Product model;
$product->validate()
and got an error:
Trying to get property of non-object
on Module::getInstance()->pattern line.
If I add module product to config bootstrap section - all works fine. But I don’t want to init this “big” module all over the site. Is it a method to init module inside only one controller/action? I’ll try to use new \ext\products\Modul() and init(), but have an error with yii\base\Module (from parent() ‘$this->controllerNamespace’ undefined. I think, this is the context problem issue.