刚开始使用 Cake PHP。我正在关注官方网站上提供的书。对于第一个博客示例,我确实创建了控制器、模型和视图,即PostsController.php
,Post.php
和index.ctp
。
LearnCake\app\Controller\PostsController.php
<?php
class PostsController extends AppController{
public $helpers = array('Html', 'Form');
public function index(){
$this->set('posts', $this->Post->find('all'));
}
}
?>
LearnCake\app\View\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; ?>
<?php unset($post); ?>
</table>
模型留空,如示例中所示:
LearnCake\app\Model\Post.php 类 Post 扩展 AppModel { }
我尝试使用此 URL 访问该页面,http://localhost/LearnCake/posts/index
但出现错误:
Missing Database Table
Error: Table p_o_s_ts for model Post was not found in datasource default.
至于示例,我确实创建了一个名为posts
. 我不明白为什么它要搜索一个名为p_o_s_t
.
我的连接文件是:
<?php
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => 'password',
'database' => 'cakephp',
'prefix' => '',
//'encoding' => 'utf8',
);
public $test = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => 'password',
'database' => 'cakephp',
'prefix' => '',
//'encoding' => 'utf8',
);
}
关于我做错了什么的任何建议?我正在使用netbeans 7.2.1
. 创建了一个名为LearnCake