コード例 #1
0
ファイル: Cats.php プロジェクト: prepare4battle/Ilch-2.0
 public function treatAction()
 {
     $categoryMapper = new CategoryMapper();
     if ($this->getRequest()->getParam('id')) {
         $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuArticle'), array('action' => 'index'))->add($this->getTranslator()->trans('menuCats'), array('action' => 'index'))->add($this->getTranslator()->trans('edit'), array('action' => 'treat'));
         $this->getView()->set('cat', $categoryMapper->getCategoryById($this->getRequest()->getParam('id')));
     } else {
         $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuArticle'), array('action' => 'index'))->add($this->getTranslator()->trans('menuCats'), array('action' => 'index'))->add($this->getTranslator()->trans('add'), array('action' => 'treat'));
     }
     if ($this->getRequest()->isPost()) {
         $model = new CategoryModel();
         if ($this->getRequest()->getParam('id')) {
             $model->setId($this->getRequest()->getParam('id'));
         }
         $name = trim($this->getRequest()->getPost('name'));
         if (empty($name)) {
             $this->addMessage('missingName', 'danger');
         } else {
             $model->setName($name);
             $categoryMapper->save($model);
             $this->addMessage('saveSuccess');
             $this->redirect(array('action' => 'index'));
         }
     }
 }
コード例 #2
0
ファイル: Category.php プロジェクト: prepare4battle/Ilch-2.0
 /**
  * Inserts or updates category model.
  *
  * @param CategoryModel $category
  */
 public function save(CategoryModel $category)
 {
     $fields = array('name' => $category->getName());
     if ($category->getId()) {
         $this->db()->update('articles_cats')->values($fields)->where(array('id' => $category->getId()))->execute();
     } else {
         $this->db()->insert('articles_cats')->values($fields)->execute();
     }
 }