示例#1
0
 /**
  * Index action method
  *
  * @return void
  */
 public function index()
 {
     $slug = substr($this->request->getRequestUri(), 5);
     if ($slug != '') {
         $tag = new Model\Tag();
         $tag->getBySlug($slug, $this->application->modules());
         if (isset($tag->id)) {
             if (count($tag->items) > $this->config->pagination) {
                 $page = $this->request->getQuery('page');
                 $limit = $this->config->pagination;
                 $pages = new Paginator(count($tag->items), $limit);
                 $pages->useInput(true);
                 $offset = null !== $page && (int) $page > 1 ? $page * $limit - $limit : 0;
                 $tag->items = array_slice($tag->items, $offset, $limit, true);
             } else {
                 $pages = null;
             }
             $this->prepareView('tags-public/tag.phtml');
             $this->template = 'tag.phtml';
             $this->view->title = 'Tag : ' . $tag->title;
             $this->view->tag_id = $tag->id;
             $this->view->tag_title = $tag->title;
             $this->view->tag_slug = $tag->slug;
             $this->view->pages = $pages;
             $this->view->merge($tag->toArray());
             $this->send();
         } else {
             $this->error();
         }
     } else {
         $this->redirect(BASE_PATH == '' ? '/' : BASE_PATH);
     }
 }
示例#2
0
 /**
  * Edit action method
  *
  * @param  int $id
  * @return void
  */
 public function edit($id)
 {
     $tag = new Model\Tag();
     $tag->getById($id);
     if (!isset($tag->id)) {
         $this->redirect(BASE_PATH . APP_URI . '/tags');
     }
     $this->prepareView('tags/edit.phtml');
     $this->view->title = 'Tags';
     $this->view->tag_title = $tag->title;
     $fields = $this->application->config()['forms']['Phire\\Tags\\Form\\Tag'];
     $fields[1]['title']['attributes']['onkeyup'] = 'phire.changeTitle(this.value);';
     $this->view->form = new Form\Tag($fields);
     $this->view->form->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($tag->toArray());
     if ($this->request->isPost()) {
         $this->view->form->setFieldValues($this->request->getPost());
         if ($this->view->form->isValid()) {
             $this->view->form->clearFilters()->addFilter('html_entity_decode', [ENT_QUOTES, 'UTF-8'])->filter();
             $tag = new Model\Tag();
             $tag->update($this->view->form->getFields());
             $this->view->id = $tag->id;
             $this->sess->setRequestValue('saved', true);
             $this->redirect(BASE_PATH . APP_URI . '/tags/edit/' . $tag->id);
         }
     }
     $this->send();
 }