RainLab\Blog\Components\Post::loadPost PHP Méthode

loadPost() protected méthode

protected loadPost ( )
    protected function loadPost()
    {
        $slug = $this->property('slug');
        $post = new BlogPost();
        $post = $post->isClassExtendedWith('RainLab.Translate.Behaviors.TranslatableModel') ? $post->transWhere('slug', $slug) : $post->where('slug', $slug);
        $post = $post->isPublished()->first();
        /*
         * Add a "url" helper attribute for linking to each category
         */
        if ($post && $post->categories->count()) {
            $post->categories->each(function ($category) {
                $category->setUrl($this->categoryPage, $this->controller);
            });
        }
        return $post;
    }

Usage Example

Exemple #1
0
 /**
  * Override of original method
  * - add the post URL to the post entity
  *
  * @return mixed
  */
 protected function loadPost()
 {
     $post = parent::loadPost();
     $postPage = $this->property('postPage');
     if ($post instanceof BlogPost) {
         $post->setUrl($postPage, $this->controller);
     }
     return $post;
 }