Anju Murali
Anju Murali

Reputation: 7

Modification of objectname of model in yii

I have a model Skill.php. In *SkillController.php * i have actionCreate method generated by crud

actionCreate(){
   $model=new Skill;
       }

when i change $model to $modelSkill it showing me error.why?

public function actionCreate()
    {
        $model=new Skill;

        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);

        if(isset($_POST['Skill']))
        {
            $model->attributes=$_POST['Skill'];
            if($model->save())
                $this->redirect(array('view','id'=>$model->skill_id));
        }

        $this->render('create',array(
            'model'=>$model,
        ));
    }

After changing to $modelSkill

public function actionCreate()
    {
        $modelSkill=new Skill;

        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($modelSkill);

        if(isset($_POST['Skill']))
        {
            $modelSkill->attributes=$_POST['Skill'];
            if($modelSkill->save())
                $this->redirect(array('view','id'=>$modelSkill->skill_id));
        }

        $this->render('create',array(
            'model'=>$modelSkill,
        ));
    }

Upvotes: 0

Views: 27

Answers (1)

Dinistro
Dinistro

Reputation: 5730

i think I found your fail. Can it be that you also replaced it in your View files? if yes, you also need to change this:

$this->render('create',array(
    'model'=>$modelSkill,
));

to this:

$this->render('create',array(
    'modelSkill'=>$modelSkill,
));

As you can see in the Yii documentation the array is going to be putted into the function extract().

Upvotes: 0

Related Questions