Posts by categories OK
This commit is contained in:
src
@ -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']);
|
||||
}
|
||||
|
||||
|
11
src/Template/Posts/by_category.ctp
Normal file
11
src/Template/Posts/by_category.ctp
Normal file
@ -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>
|
Reference in New Issue
Block a user