crowprince 2016-07-31 12:29:07 2248次浏览 5条回复 0 0 0

在模型里面的声明的变量为何一直获取不了值,而其他的变量都可以? 部分代码如下: 模型中:

//中的$psd变量获取不了值
namespace app\models;

use Yii;

/**
 * This is the model class for table "{{%user}}".
 *
 * @property integer $id
 * @property string $username
 * @property string $auth_key
 * @property string $password_hash
 * @property string $password_reset_token
 * @property string $email
 * @property integer $status
 * @property integer $created_at
 * @property integer $updated_at
 */
class User extends \app\base\core\BaseActiveRecord implements \yii\web\IdentityInterface
{
    public $psd;
    public $rememberMe;
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%user}}';
    }

}

视图中:

<?= $form->field($model, 'username')->textInput(['autofocus' => true]) ?>

<?= $form->field($model, 'psd')->passwordInput() ?>

<?= $form->field($model, 'rememberMe')->checkbox([
    'template' => "<div class=\"col-lg-offset-1 col-lg-3\">{input} {label}</div>\n<div class=\"col-lg-8\">{error}</div>",
]) ?>

控制器中:

public function actionLogin()
{
    if (!Yii::$app->user->isGuest) {
        return $this->goHome();
    }

    $model = new User();
    $ret = $model->load(Yii::$app->request->post());
    echo $model->psd.$model->username.$model->rememberMe;
    $model->scenario = 'login';
    $model->validate();
    //var_dump($model->errors);

    if ($ret && $model->login()) {
        return $this->goBack();
    }
    return $this->render('login', [
        'model' => $model,
    ]);
}
您需要登录后才可以回复。登录 | 立即注册