刚刚开始使用Cake PHP。我正在关注官方网站上提供的这本书。 对于第一个博客示例,我确实创建了控制器,模型和视图,即PostsController.php
,Post.php
和index.ctp
。cakephp:缺少数据库表博客示例
LearnCake \程序\控制器\ PostsController.php
<?php
class PostsController extends AppController{
public $helpers = array('Html', 'Form');
public function index(){
$this->set('posts', $this->Post->find('all'));
}
}
?>
LearnCake \程序\查看\文章\ 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 类柱延伸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
任何有关它为什么会默认匹配'POST'的见解?我以前见过这种类型的问题,但我认为这一天的咖啡太多了。 –
不知道为什么它可以这样做,以前从未发生过。首先想到的是,它可能是你的路线或服务器配置中的东西 - 可能设置了URL重写来匹配URL参数的“全部大写”版本。不知道,只是一个想法。 – SharkofMirkwood
好的。谢谢。 –