public function addAction() { if ($this->_status['response']['status'] && $this->_checkToken()) { $this->_status['response']['status'] = false; $this->_status['response']['code'] = 301; } $post = ['entry' => true]; if ($this->_status['response']['status'] && !$this->_getPost($post)) { $this->_status['response']['status'] = false; $this->_status['response']['code'] = 201; $this->_status['response']['detail'] = $post['empty']; } $templateList = ['title' => null, 'tag' => null, 'category' => null, 'content' => null]; $conditions = ['content']; if ($this->_status['response']['status'] && !$this->_mergeArray($this->_post['entry'], $templateList, $conditions)) { $this->_status['response']['status'] = false; $this->_status['response']['code'] = 202; $this->_status['response']['detail'] = $conditions; } if (!$this->_status['response']['status']) { return $this->response->setJsonContent($this->_status); } $posts = new Posts(); $posts->assign(['author' => $this->_id, 'title' => $this->_post['entry']['title'], 'content' => $this->_post['entry']['content']]); if (!$posts->save()) { $this->_status['response']['status'] = false; $this->_status['response']['code'] = 102; return $this->response->setJsonContent($this->_status); } if (!empty($this->_post['entry']['tag'])) { if (is_string($this->_post['entry']['tag'])) { $this->_post['entry']['tag'] = (array) $this->_post['entry']['tag']; } foreach ($this->_post['entry']['tag'] as $tag) { $tags = new Tags(); $tags->assign(['posts_id' => $posts->id, 'tag' => $tag]); if (!$tags->save()) { $this->_status['response']['status'] = false; $this->_status['response']['code'] = 102; return $this->response->setJsonContent($this->_status); } } } if (!empty($this->_post['entry']['category'])) { if (is_string($this->_post['entry']['category'])) { $this->_post['entry']['category'] = (array) $this->_post['entry']['category']; } foreach ($this->_post['entry']['category'] as $category) { $categories = new Categories(); $categories->assign(['posts_id' => $posts->id, 'category' => $category]); if (!$categories->save()) { $this->_status['response']['status'] = false; $this->_status['response']['code'] = 102; return $this->response->setJsonContent($this->_status); } } } return $this->response->setJsonContent($this->_status); }
public function addCategory($attr) { $model = new Categories(); $model->setAttributes($attr); $model->status = 1; $model->created_at = time(); $model->updated_at = time(); if ($model->save(FALSE)) { return TRUE; } return FALSE; }
public function postCreate() { # code... $validation = Validator::make(Input::all(), Categories::$rules); if ($validation->passes()) { $category = new Categories(); $category->name = Input::get('name'); $category->save(); return Redirect::to('admin/categories/index')->with('message', '新增成功'); } return Redirect::to('admin/categories/index')->with('message', '更新失敗')->withErrors($validation)->withInput(); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Categories(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Categories'])) { $model->attributes = $_POST['Categories']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function postCreate() { $category = new Categories(); $category->title = Input::get('title'); $category->content = Input::get('content'); $category->type = 'category'; $category->status = 'draft'; if ($category->save()) { return Redirect::to($this->route)->with('msg_success', Lang::get('messages.categories_create', array('title' => $category->title))); } else { return Redirect::to($this->route)->with('msg_error', Lang::get('messages.categories_create_err', array('title' => $category->title))); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Categories(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Categories'])) { $model->attributes = $_POST['Categories']; if ($model->save()) { $this->addMessage('Catgegory created successfully.'); $this->redirect(array('index')); } } $this->render('create', array('model' => $model)); }
/** * Store a newly created category in database. * * @return Response */ public function store() { $rules = array('name' => 'required'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { $messages = $validator->messages(); return Redirect::to('categories/create')->withErrors($validator)->withInput(Input::all()); } else { $category = new Categories(); $category->name = Input::get('name'); $category->description = Input::get('description'); $category->save(); return Redirect::to('categories'); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { try { $model = new Categories('create'); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Categories'])) { $model->attributes = $_POST['Categories']; if ($model->save()) { $this->redirect(array('index', 'id' => $model->id)); } } $this->render('create', array('model' => $model, 'actions' => $this->listActionsCanAccess)); } catch (Exception $e) { Yii::log("Exception " . print_r($e, true), 'error'); throw new CHttpException("Exception " . print_r($e, true)); } }
public function createAction() { if (!$this->request->isPost()) { return $this->dispatcher->forward(array("controller" => "categories", "action" => "index")); } $categories = new Categories(); $categories->id = $this->request->getPost("id"); $categories->name = $this->request->getPost("name"); $categories->slug = $this->request->getPost("slug"); if (!$categories->save()) { foreach ($categories->getMessages() as $message) { $this->flash->error((string) $message); } return $this->dispatcher->forward(array("controller" => "categories", "action" => "new")); } else { $this->flash->success("The category was created successfully"); return $this->dispatcher->forward(array("controller" => "categories", "action" => "index")); } }
public function actionAddCategory() { if (isset($_POST)) { $category = new Categories(); $category->title = $_POST['category_name']; $category->parent_id = $_POST['parent_id']; $category->layout_id = 1; $category->save(); echo Categories::getCheckBoxList(); } }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aCategoriesRelatedByCategoryId !== null) { if ($this->aCategoriesRelatedByCategoryId->isModified() || $this->aCategoriesRelatedByCategoryId->isNew()) { $affectedRows += $this->aCategoriesRelatedByCategoryId->save($con); } $this->setCategoriesRelatedByCategoryId($this->aCategoriesRelatedByCategoryId); } if ($this->aCategoriesRelatedByCategoryUpcategoryId !== null) { if ($this->aCategoriesRelatedByCategoryUpcategoryId->isModified() || $this->aCategoriesRelatedByCategoryUpcategoryId->isNew()) { $affectedRows += $this->aCategoriesRelatedByCategoryUpcategoryId->save($con); } $this->setCategoriesRelatedByCategoryUpcategoryId($this->aCategoriesRelatedByCategoryUpcategoryId); } if ($this->asfGuardUser !== null) { if ($this->asfGuardUser->isModified() || $this->asfGuardUser->isNew()) { $affectedRows += $this->asfGuardUser->save($con); } $this->setsfGuardUser($this->asfGuardUser); } if ($this->isNew()) { $this->modifiedColumns[] = AdvicePeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = AdvicePeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows += AdvicePeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } if ($this->collTagss !== null) { foreach ($this->collTagss as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collImagess !== null) { foreach ($this->collImagess as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->collCommentss !== null) { foreach ($this->collCommentss as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
/** * Adiciona uma nova categoria * @param string $categorie_name nome da nova categoria * @return boolean verdadeiro caso sucesso ou falso caso ocorra algum erro */ public function newCategorie($categorie_name) { $categorie = new Categories(); $categorie->categorie_name = $categorie_name; return $categorie->save(); }