コード例 #1
0
 public function DataAction($type = 'save')
 {
     if ($this->request->isPost()) {
         // Add
         if ($type == 'add') {
             $post = $this->request->getPost();
             $data = new MenuAction();
             if ($data->save($post)) {
                 $this->response->redirect('Result/suc/SysMenusAction');
             } else {
                 $this->response->redirect('Result/err');
             }
             // Edit
         } elseif ($type == 'edit') {
             $id = $this->request->getPost('id');
             $data = MenuAction::findFirst('id=' . $id);
             $data->name = $this->request->getPost('name');
             $data->perm = $this->request->getPost('perm');
             $data->ico = $this->request->getPost('ico');
             if ($data->save()) {
                 $this->response->redirect('Result/suc/SysMenusAction');
             } else {
                 $this->response->redirect('Result/err');
             }
             // Delete
         } elseif ($type == 'delete') {
             $id = $this->request->getPost('id');
             $arr = json_decode($id);
             foreach ($arr as $val) {
                 $data = MenuAction::findFirst('id=' . $val);
                 if ($data->delete() == FALSE) {
                     $this->response->redirect('Result/err');
                 }
             }
             $this->response->redirect('Result/suc/SysMenusAction');
         }
     } else {
         return FALSE;
     }
 }