Publication\Model\Helper\PublicationHelper::publicationBySlug PHP Метод

publicationBySlug() публичный Метод

public publicationBySlug ( $slug, $lang = null, $lifeTime = 60 )
    public function publicationBySlug($slug, $lang = null, $lifeTime = 60)
    {
        $lang = $lang ? $lang : LANG;
        $publicationResult = $this->getDi()->get('cacheManager')->load([Keys::PUBLICATION, $slug, $lang], function () use($slug, $lang, $lifeTime) {
            $columns = ['p.*', 't_slug' => 't.slug'];
            $fields = $this->translateFieldsSubQuery($lang);
            $columns = array_merge($columns, $fields);
            $qb = $this->modelsManager->createBuilder()->columns($columns)->addFrom('Publication\\Model\\Publication', 'p')->innerJoin('Publication\\Model\\Type', 'p.type_id = t.id', 't')->where('p.slug = :slug:', ['slug' => $slug]);
            $result = $qb->getQuery()->execute()->getFirst();
            return $result;
        }, $lifeTime);
        return $publicationResult;
    }

Usage Example

Пример #1
0
 public function publicationAction()
 {
     $slug = $this->dispatcher->getParam('slug', 'string');
     $type = $this->dispatcher->getParam('type', 'string');
     $publicationHelper = new PublicationHelper();
     $publicationResult = $publicationHelper->publicationBySlug($slug);
     if (!$publicationResult) {
         throw new Exception("Publication '{$slug}.html' not found");
     }
     if ($publicationResult->p->getTypeSlug() != $type) {
         throw new Exception("Publication type <> {$type}");
     }
     $this->helper->title()->append($publicationResult->meta_title);
     $this->helper->meta()->set('description', $publicationResult->meta_description);
     $this->helper->meta()->set('keywords', $publicationResult->meta_keywords);
     $this->helper->menu->setActive($type);
     $this->view->publicationResult = $publicationResult;
 }