Is it possible to populate model variables with JSON data

Suppose I have this in my controller:

public function actionEditEvent() /* ajax function */


	$event = Event::model()->findByPk($_POST['id']);


	$return_array = array(









	echo json_encode($return_array);


And in my view I have this:

$('#list').on('click', '.edit-button', function(){

	var dataId = $(this).attr('data-id');



		url: 'booking/editevent',

		type: 'POST',

		dataType: 'JSON',

		data: {id: dataId},

		success: function(result){

			$('#add-event #Event_date').val(;

			$('#add-event #Event_time').val(;

			$('#add-event #Event_comments').val(;

			$('#add-event #Event_id').val(;




As you can see in my ajax ‘success’ handler I am having to manually assign the values from the JSON object. Is it possible for this to be done in one single assignment?

#add-event is a CActiveForm

Maybe :

$.each(, function(name, value){

   if($('#add-event #Event_'+name).length > 0) 

      $('#add-event #Event_'+name).val(value);


No I mean is there any built-in Yii way of doing it?

no it isn’t.

Yii is PHP, you need a JS solution.

I know I need a JS solution. What I’m asking is whether there is any Yii helper function to do this.