/** * @usage 添加新项目 */ public function newprojectAction() { $this->view->disable(); $project_info = array(); $project_info['name'] = $this->request->getPost('project_name', 'string'); #2015-9-10目前数据库中没有对project name 做索引 $project_exits = Project::findFirst(array("name = :name:", 'bind' => array('name' => $project_info['name']))); if (isset($project_exits->name)) { #项目名称已经存在 $this->dataReturn(array('error' => '项目名称:\'' . $project_info['name'] . '\'已存在')); return; } $manager_info = array(); $manager_info['username'] = $this->request->getPost('pm_username', 'string'); #在manager表中寻找是否存在该账号的用户 $manager_exits = Manager::findFirst(array("username = :username:"******"%02d", $project_already_number + 1); } else { $project_id = $date . '01'; } } $project_info['id'] = $project_id; //添加项目状态项 $project_info['state'] = 0; foreach ($manager_info as $key => $value) { if (empty($value)) { $this->dataReturn(array('error' => '数据项不能为空' . print_r($manager_info, true))); return; } } foreach ($project_info as $key => $value) { if ($key == 'description' || $key == 'state') { continue; } if (empty($value)) { $this->dataReturn(array('error' => '数据项不能为空' . print_r($project_info, true))); return; } } #获取到代码生成的project_id; #确保manger表和project表都完成 try { AdminDB::addProject($project_info, $manager_info); } catch (Exception $e) { $this->dataReturn(array('error' => '项目创建失败')); return; } $this->dataReturn(array('flag' => true)); return; }