Exemplo n.º 1
0
 /**
  * 用户绑定到组
  */
 public function actionBind($id)
 {
     $id = (int) $id;
     $model = User::model()->findByPk($id);
     foreach ($model->groups as $g) {
         $groups[] = $g->group_id;
     }
     $rows = Group::model()->findAll();
     if ($rows) {
         $rows = \ArrHelper::model_tree($rows);
     }
     if ($_POST) {
         $group = $_POST['group'];
         //绑定用户到组
         UserGroup::UserGroupSave($id, $group);
         flash('success', __('bin user group success') . " # " . $id);
         $this->redirect(url('admin/user/index', array('id' => $id)));
     }
     return $this->render('bind', array('rows' => $rows, 'groups' => $groups, 'model' => $model, 'id' => $id, 'self' => $model->yourself));
 }
Exemplo n.º 2
0
 /**
  * 保存数据前,对pid判断,是否是正确的移动
  * 如移到到自己及自己所属的子分类将提示移动失败
  * pid 值将不会被保存
  */
 function beforeSave()
 {
     parent::beforeSave();
     if ($this->id) {
         $data = static::findAll();
         if ($data) {
             $out = ArrHelper::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;
 }