示例#1
0
 /**
  * 保存数据前,对pid判断,是否是正确的移动
  * 如移到到自己及自己所属的子分类将提示移动失败
  * pid 值将不会被保存
  */
 function beforeSave($insert)
 {
     parent::beforeSave($insert);
     if ($this->id) {
         $data = static::find()->all();
         if ($data) {
             $out = \app\core\Arr::model_tree($data, $value = 'name', $id = 'id', $pid = 'pid', $this->id);
             $out[$this->id] = $this->id;
         } else {
             $out[$this->id] = $this->id;
         }
         if ($out[$this->pid]) {
             $this->pid = $this->old_pid;
             flash('error', __('try change tree error'));
         }
     }
     return true;
 }
示例#2
0
 /**
  * 用户绑定到组
  */
 public function actionBind($id)
 {
     $id = (int) $id;
     $model = \app\modules\auth\models\User::find($id);
     foreach ($model->groups as $g) {
         $groups[] = $g->group_id;
     }
     $rows = Group::find()->all();
     if ($rows) {
         $rows = Arr::model_tree($rows);
     }
     if ($_POST) {
         $group = $_POST['group'];
         //绑定用户到组
         UserGroup::UserGroupSave($id, $group);
         flash('success', __('bin user group success') . " # " . $id);
         redirect(url('auth/group/bind', array('id' => $id)));
     }
     echo $this->render('bind', array('rows' => $rows, 'groups' => $groups, 'model' => $model, 'id' => $id, 'self' => $model->yourself));
 }