我擴展了「dektrium/yii2-user」控制器的類如下,現在我想讓$authItems
在父類的渲染視圖文件中,我應該如何傳遞這個變量?傳遞參數以查看擴展類的動作
namespace app\controllers;
use app\models\AuthItem;
use dektrium\user\controllers\RegistrationController as BaseRegistrationController;
class RegistrationController extends BaseRegistrationController
{
public function actionRegister()
{
$authItems = AuthItem::find()->all();
return parent::actionRegister();
}
}
其是主類方法
public function actionRegister()
{
if (!$this->module->enableRegistration) {
throw new NotFoundHttpException();
}
/** @var RegistrationForm $model */
$model = \Yii::createObject(RegistrationForm::className());
$event = $this->getFormEvent($model);
$this->trigger(self::EVENT_BEFORE_REGISTER, $event);
$this->performAjaxValidation($model);
if ($model->load(\Yii::$app->request->post()) && $model->register()) {
$this->trigger(self::EVENT_AFTER_REGISTER, $event);
return $this->render('/message', [
'title' => \Yii::t('user', 'Your account has been created'),
'module' => $this->module,
]);
}
return $this->render('register', [
'model' => $model,
'module' => $this->module,
]);
}
在呈現方法中什麼是視圖路徑? 它傾斜recogonize視圖我改變到 ' 返回$這 - >渲染( '用戶/註冊/註冊',[ '模式'=> $模型, '模塊'=> $這個 - >模塊, ' authItems'=> $ authItems, ]); ' 但不工作 – moh
你的註冊視圖在哪裏? ..你在哪裏放置你的註冊視圖?在哪個目錄中? – scaisEdge
@scaisEdhe它是在視圖/用戶/註冊/目錄+視圖中web.php配置文件被作爲overrided ' '視圖'=> [ '主題'=> [ '路徑映射'=> [ ' @ dektrium/user/views'=>'@ app/views/user' ], ], ],' – moh