Php 无法在yii中的控制器中获取表单值

Php 无法在yii中的控制器中获取表单值,php,Php,我正在学习YII,我遇到了一个问题。我正在尝试创建一个表单,但无法从控制器中的表单获取值。我不明白我做错了什么。 这是我的 (模型)Logindetails.php class Logindetails extends CActiveRecord { public $pass; //rest of the coding public function rules() { return array( array('password', '

我正在学习YII,我遇到了一个问题。我正在尝试创建一个表单,但无法从控制器中的表单获取值。我不明白我做错了什么。 这是我的

(模型)Logindetails.php

class Logindetails extends CActiveRecord {             
public $pass;
    //rest of the coding

public function rules() {
    return array(
        array('password', 'length', 'max'=>20),
    );
}
<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'logindetails-form',
)); ?>

<div class="row">
    <?php echo $form->labelEx($model,'pass'); ?>
    <?php echo $form->textField($model,'pass',array('size'=>20,'maxlength'=>20)); ?>
    <?php echo $form->error($model,'pass'); ?>
</div>
<div class="row buttons">
    <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
(视图)\u form.php

class Logindetails extends CActiveRecord {             
public $pass;
    //rest of the coding

public function rules() {
    return array(
        array('password', 'length', 'max'=>20),
    );
}
<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'logindetails-form',
)); ?>

<div class="row">
    <?php echo $form->labelEx($model,'pass'); ?>
    <?php echo $form->textField($model,'pass',array('size'=>20,'maxlength'=>20)); ?>
    <?php echo $form->error($model,'pass'); ?>
</div>
<div class="row buttons">
    <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>

它不断地向我显示它不存在。为什么我会有这个问题?

根据上面的代码,您只需更改控制器中的条件

if(isset($model->pass)) 

您可以调试代码以检查文本字段的值是否出现

public function actionCreate(){
    $model=new Logindetails;
    // Uncomment the following line if AJAX validation is needed
    // $this->performAjaxValidation($model);

    if(isset($_POST['Logindetails'])) {
        $model->attributes=$_POST['Logindetails'];

        print_r($model->attributes); //check either the values are coming or not.

        echo $model->pass ;

        exit; // finish here the program.

        if(isset($model->pass)) {
            echo 'its present';
        } else {
            echo 'its absent';
        }

    }

    $this->render('create',array(
        'model'=>$model,
    ));
}
我想这对你会有帮助的

谢谢。

(model)Logindetails.php

class Logindetails extends CActiveRecord {             
public $pass;
    //rest of the coding

public function rules() {
    return array(
        array('password', 'length', 'max'=>20),
    );
}
<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'logindetails-form',
)); ?>

<div class="row">
    <?php echo $form->labelEx($model,'pass'); ?>
    <?php echo $form->textField($model,'pass',array('size'=>20,'maxlength'=>20)); ?>
    <?php echo $form->error($model,'pass'); ?>
</div>
<div class="row buttons">
    <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
您必须添加规则

class Logindetails extends CActiveRecord {             
public $pass;

public function rules() {
    return array(
        array('password', 'length', 'max'=>20),
        **array('pass', 'length', 'max'=>20),**
    );
}
添加后,检查控制器中是否接收到值。

而不是echo try die($\u POST['Logindetails']['pass'])
if(isset($model->pass))