我正在學習YII,並且遇到了一個問題。我試圖創建一個表單,但無法從控制器中獲取表單中的值。我不明白我做錯了什麼。 這是我的無法在控制器中獲取表單值yii
(模型)Logindetails.php
class Logindetails extends CActiveRecord {
public $pass;
//rest of the coding
public function rules() {
return array(
array('password', 'length', 'max'=>20),
);
}
(視圖)_form.php這個
<?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(); ?>
控制器
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'];
if(isset($model->pass)) {
echo 'its present';
} else {
echo 'its absent';
}
}
$this->render('create',array(
'model'=>$model,
));
}
它不斷向我展示它缺席。爲什麼我有這個問題?
而不是echo echo die($ _ POST ['Logindetails'] ['pass']) – Kalpit