CakePHP Help with Blog Tutorial
Posted
by
Cameron
on Stack Overflow
See other posts from Stack Overflow
or by Cameron
Published on 2010-12-28T13:22:41Z
Indexed on
2010/12/28
13:54 UTC
Read the original article
Hit count: 470
I've just been following the tutorial on the CakePHP website to create a simple Blog as a way to learn a bit about Cake. However I have run into an error and not sure why as I have followed exactly what the tutorial says. The errors:
Notice (8): Undefined property: View::$Html [APP/views/posts/index.ctp, line 17]
Fatal error: Call to a member function link() on a non-object in /Users/cameron/Sites/dentist/app/views/posts/index.ctp on line 17
Here is my posts_controller
<?php
class PostsController extends AppController {
var $helpers = array('Html', 'Form');
var $name = 'Posts';
function index() {
$this->set('posts', $this->Post->find('all'));
}
function view($id = null) {
$this->Post->id = $id;
$this->set('post', $this->Post->read());
}
}
?>
and here is my model
<?php
class Post extends AppModel {
var $name = 'Post';
}
?>
and here are my views
<!-- File: /app/views/posts/index.ctp -->
<h1>Blog posts</h1>
<table>
<tr>
<th>Id</th>
<th>Title</th>
<th>Created</th>
</tr>
<!-- Here is 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'], array('controller' => 'posts', 'action' => 'view', $post['Post']['id'])); ?>
</td>
<td><?php echo $post['Post']['created']; ?></td>
</tr>
<?php endforeach; ?>
</table>
© Stack Overflow or respective owner