订购和更新功能

时间:2013-02-07 12:31:46

标签: php yii

排序和更新功能

我对更新功能没什么问题。我有一个具有ID,P_ID,PA_ID,Area_Level和Name列的表。 示例:

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          A       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 

现在我想将我的CC从父母6移到父母5,并且还要假设改变为1,2,3 ......

update.php

if($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;

位指示

public function actionUpdate($id, $idg) {
        $model = $this->loadModel($id);
        if ($model->AREA_LEVEL == 3 and $model->PARENT_AREA_ID != $idg and $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,
        ));
    }

0 个答案:

没有答案