/** * Display posts from a certain category * */ function category() { $slug = WildflowerHelper::slug($this->params['slug']); $this->WildPost->Category->Behaviors->attach('Containable'); $this->WildPost->Category->contain("Post.id"); $category = $this->WildPost->Category->findBySlug($slug); $ids = array(); foreach ($category[$this->modelClass] as $post) { $ids[] = $post['id']; } $in = implode(', ', $ids); $scope = "Post.id IN ({$in})"; $posts = $this->paginate($this->modelClass, $scope); $this->set(array('posts' => $posts, 'postsCategory' => $category)); }
/** * Create a slug from a label * * @param string $label * @return string */ private function _getMenuSlug($label) { return WildflowerHelper::slug(low($label), '-'); }