sxtuwy

sxtuwy

<strong>德才兼备,以德为先;品学兼优,品字当先;<br /> 求学之路,态度先行;莫等舰长,菜鸟先飞。</strong>

  • 财富值1645
  • 威望值0
  • 总积分1645

个人信息

  • 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,
        ));
    }
    

    昨天晚上还正常,今天晚上起来就不正常了。太怪了。
    实在不行,重新生成一次代码算了。

  • 视图:

    <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,
    		));
    	}
    }
    

    折腾了一个上午,搞不明白,为什么控制器里面无法获取表单数据

  • 发布了话题
    Yii中使用ckfinder,多个文件上传不动?
  • 舰长正解!有王者风范呀!

  • 发布了话题
    Yii::app()->request->baseUr这样写有错吗?
  • 发布了话题
    关于publish() 的再次发问
  • 没有那么自动生成的呢?肯定是先得注册到这个文件夹下,可是怎么只注册一次下次就可以引用了,至今依然是一个谜。尚无人回答。

经理 等级规则
1645/2000
资料完整度
60/100
用户活跃度
0/100

Ta的关注

0

Ta的粉丝

8

Ta的访客

52