I call a model from a component and use a component function of the same component in the model. This lead to the error “component not found” (call function on 0).
Here my questions: Is this Yii behavior normal? Should I call the component from model explicite?
A quick answer to your question is quite simple : the behavior is normal, not only for Yii but also for PHP in general. PHP code can not find anything out of the current name space.
BTW, I don’t understand what you are trying to do.
Is your ‘model’ an instance of Model or ActiveRecord?
What is authManager? What does it do? Why don’t you use the standard DbManager or PhpManager?
What does ‘call a model from a component’ and ‘use a component function of the same component in the model’ mean? Can you show us the relevant code?
authManager is my component, I use the DbManager also. authManager is more specific for my application and has more functions like encryption, no matter.
I think the current code should work, if your authManager has those static methods of can() and get(). Does it still break?
And, a silly question, maybe, but is it really authManager and not AuthManager? Is it stored in authManager.php? Your code might be broken in config, not in getBranches method. Did you check the call stack?
Yii-Debugger says with Yii::$app->auth->can(): “Call to a member function can() on null”
Now I use the direct call of the component: \app\components\authManager::can()
I believe it’s an issue with the recursive call of the component and its not a namespace problem because all other of my components works well in this model.