Example #1
0
 public function actionAdd()
 {
     if (Yii::app()->request->isPostRequest) {
         $user = new IMUsers();
         $data = Yii::app()->request->getPost('data');
         $user->attributes = $data;
         $user->pwd = md5($data['pwd']);
         if ($_FILES['data']['tmp_name']['mod_avatar']) {
             $user->avatar = $this->upload('data[mod_avatar]');
         } else {
             $user->avatar = '';
         }
         $time = time();
         $user->departId = $data['departId'];
         $user->status = $data['status'];
         $user->created = $time;
         $user->updated = $user->created;
         if ($user->save()) {
             $this->showAlert('success', '添加成功');
             $this->getUserCache();
         } else {
             $this->showAlert('fail', '添加失败,请添加完整信息');
         }
     }
     $departs = Yii::app()->cache->get('cache_depart');
     if (empty($departs)) {
         $departs = $this->getDepartCache();
     }
     $this->render('add', array('departs' => $departs));
 }