protected function processForm(sfWebRequest $request, ProjectForm $form) { $form->bind($request->getParameter($form->getName())); if ($form->isValid()) { $object = $form->save(); $redirectTo = array('sf_route' => 'project_edit', 'sf_subject' => $object); if ($request->getParameter('save_and_add')) { $redirectTo = '@project_new'; } $this->redirect($redirectTo); } }
public function setDefaultForm($title, $form = "default") { sfContext::getInstance()->getLogger()->info("Setting defaults for form [" . $title . "], setting form to (" . $form . ")"); // TODO: Going to sleep now, but seems like we need to prepend the title of the form before the form - "main_default" insted of just "default" // TODO: Maybe it's lack of sleep, but title<->form are mixed up, it seems $setting = ProjectSettingPeer::retrieveByProjectIdTitle($this->getId(), $title); if ($setting == null) { sfContext::getInstance()->getLogger()->info("Setting not found when setting default (normal behavior)"); $setting = new ProjectSetting(); $setting->setProjectId($this->getId()); $setting->setTitle('form_' . $title); $setting->setSetting($form); $setting->save(); } $new_form = ProjectFormPeer::retrieveByProjectIdTitle($this->getId(), $setting->getSetting()); if ($new_form == null) { sfContext::getInstance()->getLogger()->info("Form not found (normal behavior)"); $new_form = new ProjectForm(); $new_form->setProjectId($this->getId()); $new_form->setTitle($form); $new_form->save(); } sfContext::getInstance()->getLogger()->info("Form created, setting assigned. "); return $form; }
/** * 个人作品 */ public function actionPersonart() { //暂时不开放公益项目的分布 $errorarray = array(0 => 'fail', 1 => '暂时不开放当前类型项目发布!', 2 => 'reurl', 3 => Yii::app()->request->urlReferrer, 4 => '/notice/errors.html'); //跳转到错误的页面 parent::toUrl($errorarray); Yii::app()->end(); $this->layout = "//layouts/member_html5"; $error = ""; if (isset($_POST['title'])) { //发布项目处理 $_POST['type'] = 2; $va_param = $_POST; unset($va_param['publis_submit']); unset($va_param['picname']); Yii::import("application.models.form.ProjectForm", true); //形象图片处理 $attch = CUploadedFile::getInstanceByName("picname"); $error = ""; if ($attch == null) { $name = Yii::app()->theme->baseUrl . "/images/projectdefault.png"; } elseif ($attch->size > 1024 * 1024) { $error = "形象图片不超过1M"; } elseif (!in_array(strtolower($attch->extensionName), array("jpeg", "jpg", "gif", "png"))) { $error = "上传的图片格式不正确"; } else { $filename = "user_" . Yii::app()->user->getId() . "_" . time() . "." . strtolower($attch->extensionName); $path = "/data/upload/project/" . date("Y-m-d") . "/"; $filepath = Yii::getPathOfAlias('webroot') . $path . $filename; $name = $path . $filename; if (BaseTool::createFolder($path)) { if (!$attch->saveAs($filepath)) { $error = "形象图片上传出错"; } } } if (empty($error)) { $va_param['litt_pic'] = $name; $oneProjectForm = new ProjectForm(); $oneProjectForm->scenario = 'art'; $oneProjectForm->setAttributes($va_param); if ($oneProjectForm->validate()) { $oneProjectForm->save($va_param); $this->redirect("/member/projects/publishing.html"); Yii::app()->end(); } else { $errorarray = $oneProjectForm->getErrors(); $error = current(current($errorarray)); } } } $this->pageTitle = "发布项目-" . Yii::app()->name; $this->render('personart', array("publish_error" => $error)); }