Hello community,
I just follow the howTo for a new behaviour on a class extended of ActiveRecord.
Here the Behaviour class in “common\components” directory:
<?php
namespace app\components;
use yii\base\Behavior;
use yii\db\BaseActiveRecord;
class i18nBehavior extends Behavior
{
public function events(): array
{
return [
BaseActiveRecord::EVENT_AFTER_FIND => 'translate',
];
}
public function translate($event): void
{
// Do something
}
}
and here the attach in the class:
public function behaviors(): array
{
return [['class' => i18nBehavior::class]];
}
but I’m getting this error when running:
Not instantiable – yii\di\NotInstantiableException
Failed to instantiate component or class "app\components\i18nBehavior".
↵
Caused by: ReflectionException
Class "app\components\i18nBehavior" does not exist
in /app/vendor/yiisoft/yii2/di/Container.php at line 507
I can’t find why?
Thank you.