【发布时间】:2014-12-08 12:57:51
【问题描述】:
我已经开发了允许所有者创建团队的表格。代码是:
<?php $form = ActiveForm::begin(['id' => 'team-create-form', 'action' => ['site/create-team-form'], 'options' => array('role' => 'form')]);
<div class="col-lg-10 form-group" id="createTeamForm" style="margin-top: 15px;">
<div class="col-lg-4">
<?= $form->field($model, 'team_name',['template' => "{label}\t{input}\n{error}"])->textInput(array('placeholder'=>'Enter team name....')); ?>
</div>
<div class="col-lg-4">
<?= $form->field($model, 'team_description',['template' => "{label}\t{input}\n{error}"])->textInput(array('placeholder'=>'Enter team Description....')); ?>
</div>
<div class="col-lg-2">
<?= Html::submitButton('Submit', ['class' => 'btn btn-danger', 'id' => 'tsubmit', 'style' => 'margin-top: 22.5px; margin-right: 15px;']) ?>
</div>
</div>
我已尝试使用上述代码加载页面,但它显示错误“$model not defined”。如何解决。我需要在 main-local.php 中添加一些东西吗???
public function actionLogin()
{
$model = new LoginForm();
$session = Yii::$app->session;
if ($model->load(Yii::$app->request->post()) && $model->login()) {
$collection1 = Yii::$app->mongodb->getCollection('users');
$teamid = $collection1->findOne(array('username' => $model->email_address));
$session->set('id', $teamid['_id']);
$session->set('name', $teamid['name']);
$session->set('username', $model->email_address);
$collection2 = Yii::$app->mongodb->getCollection('teamdashboard');
$teams = $collection2->find(array('admin' => $model->email_address));
$model1 = new TeamCreateForm();
return $this->render('dashboard', ['model'=>$model1, 'teams'=> $teams]);
} elseif($session->isActive){
$username = $session->get('username');
$collection = Yii::$app->mongodb->getCollection('users');
$teams = $collection->findOne(array('username' => $username));
return $this->render('dashboard', ['teams'=>$teams]);
}else{
$this->layout = 'index';
return $this->render('login', ['model' => $model]);
}
}
为了更好地理解,我已将产品页面重命名为仪表板。
现在,当我运行此程序并登录时,地址栏 url 显示 url:..../web/index.php?r=site/login 而它应该显示 url:..../web/index .php?r=site/dashboard & 显示仪表板的视图。
当我刷新页面时,我将我带回登录...
【问题讨论】:
-
你要发送 $model 来查看吗??
-
如果我这样做,我不会将 $model 发送到视图 bcoz,那么地址栏上的 url 将保持与仪表板之前的相同。这会导致问题。
-
我同意@Mihai,请仔细阅读文档yiiframework.com/doc-2.0/guide-structure-views.html
标签: yii2