突然间,yii怎么也无法获取到表单提交的数据 [ 新手入门 ]
真是搞的不明白,突然间yii无法获取表单提交的数据?搞不懂是什么原因,各位有遇到过这种问题吗?说一说经验吧。
共 4 条回复
-
视图:
<div class="pageFormContent nowrap" layoutH="10"> <?php $form=$this->beginWidget('CActiveForm', array( 'id'=>'classroom-form', 'enableAjaxValidation'=>false, 'htmlOptions'=>array('onsubmit'=>'return validateCallback(this,dialogAjaxDone)','class'=>'pageForm required-validate'), )); ?> <p class="note">带<span class="required">*</span>号的字段是必填的.</p> <?php echo $form->errorSummary($model); ?> <dl> <dt><?php echo $form->labelEx($model,'title'); ?></dt> <dd><?php echo $form->textField($model,'title',array('size'=>8,'maxlength'=>8,'class'=>'required')); ?></dd> <dd><?php echo $form->error($model,'title'); ?></dd> </dl> <dl> <dt> <?php echo $form->labelEx($model,'grade_id'); ?></dt> <dd><?php echo $form->textField($model,'grade_id',array('size'=>8,'maxlength'=>8,'class'=>'required')); ?></dd> <dd> <?php echo $form->error($model,'grade_id'); ?></dd> </dl> <dl> <dt><?php echo CHtml::submitButton($model->isNewRecord ? '创建' : '保存'); ?></dt> </dl> <?php $this->endWidget(); ?> </div><!-- form -->
模型:
<?php /** * This is the model class for table "{{classroom}}". * * The followings are the available columns in table '{{classroom}}': * @property integer $id * @property string $title * @property string $grade_id */ class Classroom extends CActiveRecord { /** * Returns the static model of the specified AR class. * @param string $className active record class name. * @return Classroom the static model class */ public static function model($className=__CLASS__) { return parent::model($className); } /** * @return string the associated database table name */ public function tableName() { return '{{classroom}}'; } /** * @return array validation rules for model attributes. */ public function rules() { // NOTE: you should only define rules for those attributes that // will receive user inputs. return array( //array('title, grade_id', 'required'), //array('title, grade_id', 'length', 'max'=>8), // The following rule is used by search(). // Please remove those attributes that should not be searched. array('id, title, grade_id', 'safe', 'on'=>'search'), ); } /** * @return array relational rules. */ public function relations() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array( 'nianji' => array(self::BELONGS_TO, 'Grade', 'grade_id'),//班级属于年级 'student' => array(self::HAS_MANY, 'Student', 'classroom_id', 'condition'=>'classrooms.id=students.classroom_id','order'=>'classrooms.id DESC'), 'studentCount' => array(self::STAT, 'Student', 'classroom_id', 'condition'=>'classroom_id=classrooms.id'), ); } /** * @return array customized attribute labels (name=>label) */ public function attributeLabels() { return array( 'id' => 'ID', 'title' => 'Title', 'grade_id' => 'Grade', ); } /** * Retrieves a list of models based on the current search/filter conditions. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. */ public function search() { // Warning: Please modify the following code to remove attributes that // should not be searched. $criteria=new CDbCriteria; $criteria->compare('id',$this->id); $criteria->compare('title',$this->title,true); $criteria->compare('grade_id',$this->grade_id,true); return new CActiveDataProvider($this, array( 'criteria'=>$criteria, )); } }
折腾了一个上午,搞不明白,为什么控制器里面无法获取表单数据
-
public function actionCreate() { $model=new Classroom; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if(isset($_POST['Classroom'])) { $model->attributes=$_POST['Classroom']; if($model->save()) $this->redirect(array('view','id'=>$model->id)); } $this->render('create',array( 'model'=>$model, )); }
昨天晚上还正常,今天晚上起来就不正常了。太怪了。
实在不行,重新生成一次代码算了。 -
world_voice 回复于 2012-09-08 13:02 举报
我也出现这问题了,我把
'onsubmit'=>'return validateCallback(this,dialogAjaxDone)'
注释掉后就能获取了,但是,onsubmit就不能用了,求怎么办?
sxtuwy 山西
注册时间:2011-07-24
最后登录:2013-06-04
在线时长:0小时0分
最后登录:2013-06-04
在线时长:0小时0分
- 粉丝8
- 金钱1645
- 威望0
- 积分1645