1
0

Posts by categories OK

This commit is contained in:
Anthony Gourd
2016-12-01 22:16:14 +01:00
parent 40f6d390b1
commit d9eb91e065
2 changed files with 14 additions and 2 deletions
src
Controller
Template

@ -44,11 +44,12 @@ class PostsController extends AppController
$this->set('_serialize', ['post']);
}
public function list($category_id) {
public function byCategory($category_id) {
$posts = $this->Posts->find()->where(['category_id' => $category_id]);
$category = $this->Posts->Categories->get()
$category = $this->Posts->Categories->get($category_id);
$this->set('posts', $posts);
$this->set('category', $category);
$this->set('_serialize', ['posts']);
}

@ -0,0 +1,11 @@
<div class="row">
<h5>Posts in relation with <?= $category->name ?></h5>
<ul>
<?php foreach($posts as $post): ?>
<li>
<h6><?= $post->title ?></h6>
<p><?= $post->body ?></p>
</li>
<?php endforeach; ?>
</ul>
</div>