剛剛開始使用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
好的。謝謝。 –