我安装了cakephp 2.9.7,我正在通过引用(https://book.cakephp.org/2.0/en/tutorials-and-examples/blog/part-two.html)做博客教程。
创建 Post 模型
class Post extends AppModel {
}
创建 Post Controller
class PostsController extends AppController {
public $helpers = array('Html', 'Form');
public function index() {
$this->set('posts', $this->Post->find('all'));
}
}
创建帖 subview 。我在 app/View 文件夹中创建了 Posts 文件夹。并且我也更新了 Database.php,以便它可以连接到 mysql 数据库。
<!-- File: /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>
但是当我在本地 cakephp/app 中运行时出现错误 错误:找不到 AppController::index() 的 View 。请确认您已在以下路径之一中创建了文件:App/index.ctp: cakephp/app/View/App/index.ctp.stuck 解决了这个问题,因为我是 cakephp 的新手。
最佳答案
您似乎请求了错误的 URL。如果您要求http://your-domain.de/app
Cake 将尝试查找 index
的操作和 View AppController
的.
您应该通过请求 http://your-domain.de/posts
获得所需的 Controller 和 View 或http://your-domain.de/posts/index
.
关于php - Cakephp博客教程-添加一层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43201687/