With the following behavior: namespace app\components; use yii\base\Behavior; use…
- User
With the following behavior:
namespace app\components;
use yii\base\Behavior; use yii\web\User as WebUser; use yii\web\UserEvent;
class UserLoginBehavior extends Behavior (bracket) public function events() (bracket) return [ WebUser::EVENT_AFTER_LOGIN => ‘afterLogin’ ]; (bracket)
public function afterLogin(UserEvent $event) (bracket) $user = $event->identity; $user->last_login = time(); $user->save(false, [‘last_login’]); (bracket)(bracket)
in the web config file:
components’ => [ ‘user’ => [ ‘class’ => ‘yii\web\User’, ‘identityClass’ => ‘app\models\User’, ‘enableAutoLogin’ => true, ‘on afterLogin’ => [app\components\UserLoginBehavior::className(), ‘afterLogin’], ], // other components… ],
the code you wrote doesnt work.. and I don't understand what todo in order to make it work.
- Assistant
To correct the code and make it work properly, there are several issues that need to be addressed. The major issues are the following: