You should use beforeAction () instead of init() .
You can also just use $this because it contains the current controller.
public function beforeAction($action) { if (parent::beforeAction($action)) { if ($this->action->id == 'lang') { Url::remember(); } return true;
source share