public function createAction() { $this->useJsonResponse(); if ($this->request->isPost()) { if ($id = $this->request->getPost('id', 'int')) { $about = About::findFirstById($id); } else { $about = new About(); } $about->assign(array('name' => $this->request->getPost('name', 'striptags'), 'fullName' => $this->request->getPost('fullName', 'striptags'), 'engName' => $this->request->getPost('engName', 'striptags'), 'address' => $this->request->getPost('address', 'striptags'), 'level' => $this->request->getPost('level', 'int'), 'category' => $this->request->getPost('category', 'int'), 'contacts' => $this->request->getPost('contacts', 'striptags'), 'phone' => $this->request->getPost('phone', 'striptags'), 'create_at' => $this->request->getPost('create_at', 'striptags'), 'email' => $this->request->getPost('email', 'email'), 'intro' => $this->request->getPost('intro', 'striptags'))); } if (!$about->save()) { return $this->flashError($about->getMessages()); } else { return $this->flashSuccess('添加成功'); } }
public function initialize($entity = null, $options = array()) { if (!isset($options['edit'])) { $id = new Text('id'); $this->add($id->setLabel("Id")); } else { $id = new Hidden('id'); $this->add($id); } $name = new Text('name'); $name->setLabel('简称'); $this->add($name); $fullName = new Text('fullName'); $fullName->setLabel('全称'); $this->add($fullName); $engName = new Text("engName"); $engName->setLabel('英文名称'); $this->add($engName); $address = new Text('address'); $address->setLabel('机构地址'); $this->add($address); $level = new Select('level', About::getLevels()); $level->setLabel('级别'); $this->add($level); $category = new Select('category', About::getCategories()); $category->setLabel('分类'); $this->add($category); $contacts = new Text('contacts'); $contacts->setLabel('业务联系人'); $this->add($contacts); $phone = new Text('phone'); $phone->setLabel('联系人电话'); $this->add($phone); $email = new Text('email'); $email->setLabel('邮箱'); $this->add($email); $intro = new TextArea('intro'); $intro->setLabel('简介'); $this->add($intro); $create_at = new Text('create_at'); $create_at->setLabel('建馆日期'); $this->add($create_at); }