I have a
Controller/PostsController.php
Model/Post.php
View/Posts/Index.ctp
if anyone has followed the cakephp blog tutorial i have completed that. Anyone who hasnt, its basically a site that lets you add a title and a comment. Much like a forum.
Now i have this set up , but i want to include a new page called home. And on this page i wont to display the forum i created but in a smaller container.
I am unsure how to add the view of Posts to a new controller/model/view.
This is PostsController.php:
class PostsController extends AppController {
public function index() {
$this->set('posts', $this->Post->find('all'));
}
}
This is View/Posts/index.ctp
<table>
<tr>
<th>Id</th>
<th>Title</th>
<th>Actions</th>
<th>Created</th>
</tr>
<!-- Here's where we loop through our $posts array, printing out post info -->
<?php foreach ($posts as $post): ?>
<tr>
<td><?php echo $post['Post']['id']; ?></td>
<td>
<?php
echo $this->Html->link(
$post['Post']['title']
);
?>
</td>
<td>
<?php echo $post['Post']['created']; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
so with this, how do i get the same posts to include on a new controller and view, lets say:
HomesController.php View/Homes/index.ctp
EDIT//EDIT//EDIT
right i have managed to do half of this now by adding $this->render('/Abouts/index'); to my PostsController
but now i get an error saying "Undefined variable: posts [APP\View\Abouts\index.ctp, line 12]"
im not sure how to define these in my abouts view