コード例 #1
0
	public function addAction()
	{
		$addForm = new Project_Forms_ProjectSave();
		$projects = new Project_Models_ProjectMapper();
		$structypes = new General_Models_StructypeMapper();
		$addForm->submit->setLabel('保存继续新建');
		$addForm->submit2->setLabel('保存返回上页');
		$errorMsg = null;
		$structypes->populateStructypeDd($addForm);
		$addForm = $projects->formValidator($addForm,0);
			
		if($this->getRequest()->isPost())
		{
			$btClicked = $this->getRequest()->getPost('submit');
			$formData = $this->getRequest()->getPost();
			if($addForm->isValid($formData))
			{
				$array = $projects->dataValidator($formData,0);
				$trigger = $array['trigger'];
				$errorMsg = $array['errorMsg'];
				if($trigger == 0)
				{
					$project = new Project_Models_Project();
					$project->setName($addForm->getValue('name'));
					$project->setAddress($addForm->getValue('address'));
					$project->setStatus($addForm->getValue('status'));
					$project->setStructype($addForm->getValue('structype'));
					$project->setLevel($addForm->getValue('level'));
					$project->setPeriod($addForm->getValue('period'));
					$project->setStartDate($addForm->getValue('startDate'));
					$project->setContactId($addForm->getValue('contactId'));
					$project->setConstructor($addForm->getValue('constructor'));
					$project->setContractor($addForm->getValue('contractor'));
					$project->setSupervisor($addForm->getValue('supervisor'));
					$project->setDesigner($addForm->getValue('designer'));
					$project->setLicense($addForm->getValue('license'));
					$project->setAmount($addForm->getValue('amount'));
					$project->setConstrArea($addForm->getValue('constrArea'));
					$project->setRemark($addForm->getValue('remark'));
					$projects->save($project);
					$errorMsg = General_Models_Text::$text_save_success;
					if($btClicked == '保存继续新建')
					{
						$addForm->reset();
						}
						else
						{
							$this->_helper->flashMessenger->addMessage('对工程: '.$project->getName().'的新建成功。');
							$this->_redirect('/project');
							}
					}
					else
					{
						$addForm->populate($formData);
						}
				}
				else
				{
					$addForm->populate($formData);
					}
		}
		$this->view->errorMsg = $errorMsg;
		$this->view->addForm = $addForm;
	}