Ordering Models by Weight with CJuiSortable

Comparing #3 with #4

Content

[...]
// Add a Submit button to send data to the controller
echo CHtml::ajaxButton('Submit Changes', '', array(
'type' => 'POST',
'data' => array(
// Turn the Javascript array into a PHP-friendly string
'Order' => 'js:$("ul
#orderList.ui-sortable").sortable("toArray").toString()',
)
));
[...]
if ($model = YourClass::model()->findbyPk($models[$i]))
{
$model->weight = $i;
 
 
                $model->save(
// Use updateByPK to avoid running model validate
 
                $model->updateByPk( $models[$i],array("weight"=>$i) 
);
}
}
}
// Handle the regular model order view
else
[...]