Yii Framework Forum: Sharing An Action For Post And Ajax Methods - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Sharing An Action For Post And Ajax Methods Rate Topic: -----

#1 User is offline   msoa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 248
  • Joined: 15-August 12

Posted 19 March 2013 - 04:05 AM

The following code is appropriate to sharing an action for Post and Ajax methods?
The main goal is quality of code and performance?

    public function actionUpdate()
    {
        $model=$this->loadModel(Yii::app()->user->id);
        $model->scenario = 'updateProfile';
        $this->performAjaxValidation($model);

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

            if($model->validate())
                if($model->save()){
                    if(Yii::app()->request->isAjaxRequest)
                        Yii::app()->end('saved');
                    else{
                        Yii::app()->user->setFlash('status','saved');
                    }
                }

            if(Yii::app()->request->isAjaxRequest)
                if(!$model->validate())
                    Yii::app()->end('!validate');
        }
        $this->render('update',array('model'=>$model));
    }

0

#2 User is offline   Lal Zada 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 125
  • Joined: 06-November 12
  • Location:Lahore, Pakistan

Posted 19 March 2013 - 05:23 AM

Yeah !!!
its OK.... i always used this methodology<br>
Is it fast? Is it secure? Is it professional? Is it right for my next project? Yes, it is

Linkedin Facebook Twitter Google+
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users