Example #1
0
 /**
  * Displays post by category
  * @param  [int] $categoryId    [description category id]
  * @param  [string] $slug       [description slug seo]
  * @return [array]              [list all object ]
  */
 public function categoryAction($categoryId, $slug)
 {
     $category = Categories::findFirstById($categoryId);
     if (!$category) {
         $this->flashSession->notice('The category doesn\'t exist');
         return $this->response->redirect();
     }
     $numberPage = 1;
     if ($this->request->getQuery("page", "int")) {
         $numberPage = $this->request->getQuery("page", "int");
     }
     $posts = Posts::find("categoriesId = '{$categoryId}'");
     $paginator = new Paginator(array("data" => $posts, "limit" => 10, "page" => $numberPage));
     $this->view->page = $paginator->getPaginate();
     $this->view->categories = Categories::find();
 }
Example #2
0
 public function initialize($entity = null, $options = null)
 {
     //In edition the id is hidden
     if (isset($options['edit']) && $options['edit']) {
         $id = new Hidden('id');
     } else {
         $id = new Text('id');
     }
     $this->add($id);
     //$title = new Text('title');//<input type="text" value="" id="username" name="username">
     $title = new Text('title', array('placeholder' => 'Enter title', 'class' => 'span10'));
     $title->setLabel('Title');
     //<label for="username">Username</label>
     $title->addValidators(array(new PresenceOf(array('message' => 'The title is required'))));
     $this->add($title);
     $this->add(new Text('tags', array('placeholder' => 'tags')));
     $content = new TextArea('content', array('placeholder' => ' Enter text ...', 'class' => 'span10', 'rows' => '10', 'cols' => '80'));
     $content->addValidator(new PresenceOf(array('message' => 'The content is required')));
     $this->add($content);
     $categories = new Select('categoriesId', Categories::find(), array('using' => array('id', 'name'), 'useEmpty' => true, 'emptyText' => '----', 'emptyValue' => ''));
     $this->add($categories);
 }
Example #3
0
 public function initialize($entity = null, $options = null)
 {
     //In edition the id is hidden
     if (isset($options['edit']) && $options['edit']) {
         $id = new Hidden('id');
     } else {
         $id = new Text('id');
     }
     $this->add($id);
     $fileCaption = new Text('fileCaption', array('placeholder' => $this->request->getPost('fileCaption')));
     $fileCaption->setLabel(_('Caption'));
     $fileCaption->addValidators(array(new PresenceOf(array('message' => _('Document caption not null')))));
     $this->add($fileCaption);
     $fileData = new File('fileData');
     $fileData->setLabel('Document upload');
     /*$fileData->addValidators(array(
     			new PresenceOf(array(
     				'message' =>_('Document file required')
     				))
     		));*/
     $this->add($fileData);
     //render if action is edit
     $fileDataEdit = new File('fileDataEdit');
     $fileDataEdit->setLabel('Document upload');
     /*$fileData->addValidators(array(
     			new PresenceOf(array(
     				'message' =>_('Document file required')
     				))
     		));*/
     $this->add($fileDataEdit);
     $categories = new Select('categoriesId', Categories::find(), array('using' => array('id', 'name'), 'useEmpty' => true, 'emptyText' => '----', 'emptyValue' => ''));
     $categories->setLabel('Categories');
     $this->add($categories);
     $description = new TextArea('description', array('placeholder' => ' Enter text ...', 'class' => 'span8', 'rows' => '6'));
     $description->addValidator(new PresenceOf(array('message' => _('The description is required'))));
     $description->setLabel('Description');
     $this->add($description);
     $this->add(new Text('q', array('placeholder' => $this->request->getPost('q', 'striptags'))));
 }
Example #4
0
 public function deleteAction($id)
 {
     $categories = Categories::findFirstById($id);
     if (!$categories) {
         $this->flash->error(_("Ucategories was not found"));
         return $this->dispatcher->forward(array('action' => 'index'));
     }
     if (!$categories->delete()) {
         $this->flash->error($categories->getMessages());
     } else {
         $this->flash->success(_("Categories was deleted"));
     }
     return $this->dispatcher->forward(array('action' => 'index'));
 }