php - Cakephp博客教程-添加一层

标签 php mysql cakephp

我安装了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/

相关文章:

php - 有没有更好的方法来保护特定网页?

mysql - 如何从 MySql Workbench 连接到互联网中的 MySql 服务器?

mysql - 在 SQL 中使用表作为变量

php - 如何修复Wamp服务器中的错误 “Uncaught Error: Call to undefined function oci_connect()”?

php - 如何在htaccess中创建类似YouTube的短域重定向?

php - 由于模板提供的脚本,CSS 无法加载

mysql - 限制符号的数据类型?

php - 你如何更新 PHP 中的 cookie?

cakephp - 从 AppExceptionHandler 渲染 View

cakephp 1.1 与 php 5.3