0

Hi I am using the third field in the login form my login form code look like this

<div class="row">
<?php echo $form->labelEx($model,'username'); ?>
<?php echo $form->textField($model,'username'); ?>
<?php echo $form->error($model,'username'); ?>
</div>

<div class="row">
    <?php echo $form->labelEx($model,'password'); ?>
    <?php echo $form->passwordField($model,'password'); ?>
    <?php echo $form->error($model,'password'); ?>

</div>

<div class="row">
    <?php   echo $form->labelEx($model,'userrole'); ?>
    <?php 
        $data = Userrole::model()->findAll();
        echo $form->dropDownList($model, 'userrole', CHtml::listData($data, 'id', 'userType'));
    ?>
    <?php echo $form->error($model,'userrole'); ?>
</div>

here i should pass the third parameter to authenticate the user so how to pass to the UserIdentity class. UserIdentity class defined only username, password attributes so it will get only the username and password so, how to get the third one

4

1 に答える 1

2

CUserIdentity のコンストラクターは単なるセッターです。したがって、次の変更を加えて userole を CUserIdentity に渡すことができます

1) フォームを更新します (LoginForm だと思いますか?) public $userrole;

次に、認証メソッドで、UserIdentity への呼び出しを更新して userrole を含めます。

$this->_identity=new UserIdentity($this->username,$this->password, $this->userrole);

次に、UserIdentity.php ファイルに以下を追加します。

public $userrole;
public function __construct($username, $password, $userrole)
{
    $this->username = $username;
    $this->password = $password;
    $this->userrole = $userrole;
}

少し微調整する必要があるかもしれませんが、それが変数を渡すために必要なことの一般的な要点です。Form::rules() 配列を更新して、userrole が適切に検証されるようにしてください。

于 2013-02-16T01:06:59.503 に答える