php - Order by and update function -
order , update function
i have little problem update function. have table has id, p_id, pa_id,area_level , name columns. example:
id p_id parent area_level name sort --------------------------------------------------- 1 11 null 1 m1 1 2 22 null 1 m2 2 3 33 null 1 m3 3 4 11 1 2 1 5 11 2 2 b 1 6 11 2 2 c 2 7 11 4 3 aa 1 8 11 5 3 bb 1 9 11 6 3 cc 1
now suppose move cc parent 6 parent 5 , sort suppose change, 1,2,3...
update.phpif($model->area_level==3){ $g = $model->parent_area_id; $m = wppareas::model()->getgroupnames($model->package_id, wppareas::model()->findbypk($g)->parent_area_id); $list = chtml::listdata($m, 'id', 'area_name'); $select =$idg; echo chtml::dropdownlist('id', $select, $list, array('empty' => 'odaberi grupu','onchange' => 'document.location.href = "/pepa/index.php?r=wppareas/update&id='.$id.'&idg="+ this.value')); echo $select;
contoller public function actionupdate($id, $idg) { $model = $this->loadmodel($id); if ($model->area_level == 3 , $model->parent_area_id != $idg , $idg != -1) { $model->parent_area_id = $idg; $model->order_by = count(wppareas::model()->getsubgroupnames($model->package_id, $idg)) + 1; $model->order_by; $sort = new csort(); $sort->attributes = array( 'sort'=>'order_by asc', ); } if (isset($_post['wppareas'])) { $model->attributes = $_post['wppareas']; if ($model->save()) $this->redirect(array('view', 'id' => $model->id)); } $this->render('update', array( 'model' => $model, 'id' => $id, 'idg' => $idg, )); }
php yii
No comments:
Post a Comment