I Have Problem To Updat Just One Filed Using Save()

Hello all

Sometimes we want to update just one or some fields of table, instead of update all fields.

I have trouble with the following syntax! [b]Since it updates all loaded fields from table in the DB.

[/b]




	/**

	 * Shows the Control panel of User

	 */

	public function actionIndex()

	{

		$user=$this->loadUser(Yii::app()->user->id); // Loads $user & $user->u_prof tables fron DB

		if (empty($user->u_prof))

			throw new CHttpException(403,'The user has not created profile yet.');

		

		// Save UserProfile->note value from forms

		if (isset($_POST['UserProfile'])) { // save $user->u_prof->note

			$user->u_prof->attributes= $_POST['UserProfile'];

			$user->u_prof->save(true,array('note'));

			}

			

		$this->render('index',array(

			'user'=>$user,

		));

	}



also the code below doesn’t work too, seems the syntax is not correct!




		// Save $user->u_prof->note values received from a form by post method

		// u_prof is a relation defigned in User model, point to UserProfile model.

		if (isset($_POST['UserProfile'])) {

			$user->u_prof->update (array(

				'condition'=>'uid='.Yii::app()->user->id,

				array('note'=>':note'),

				'params' => array(':note'=>$_POST['UserProfile']['note'),

				));

			}



Note: i wanna update only one field ‘$user->u_prof->note’ in database, while it is filtered against SQL injection. you see i have tried to use


'params' => array(':note'=>$_POST['UserProfile']['note']

i’ll be glad if some body writes the correct syntax to save ONLY ‘note’ field of table in the DB.

no body wanna help me?!

Hey use this code this will work for you


$model_1 =User::model()->findByAttributes(array('uid='.Yii::app()->user->id));


$model_1->note  = $_POST['UserProfile']['note'];

$model_1->save(false);



I hope this will work for you