douqiang3768 2017-04-04 08:10
浏览 23
已采纳

Cakephp博客教程 - 添加图层

I installed cakephp 2.9.7 and i am doing blog tutorial by referring(https://book.cakephp.org/2.0/en/tutorials-and-examples/blog/part-two.html).

Create a Post model

class Post extends AppModel {
}

Creating a Post controller

class PostsController extends AppController {
    public $helpers = array('Html', 'Form');

    public function index() {
        $this->set('posts', $this->Post->find('all'));
    }
}

Creating Post Views.I created Posts folder inside app/View folder.And i updated Database.php too so that it can connect to mysql database.

<!-- 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>

But when i run in my local cakephp/app error says Error: The view for AppController::index() was not found.Confirm you have created the file: App/index.ctp in one of the following paths: cakephp/app/View/App/index.ctp.stuck with solving this as i am new to cakephp.

  • 写回答

1条回答 默认 最新

  • duandang2838 2017-04-04 08:46
    关注

    Seems like you are requesting the wrong URL. If you request http://your-domain.de/app Cake will try to find the Action and View for index of the AppController.

    You should get your desired Controller and View by requesting http://your-domain.de/posts or http://your-domain.de/posts/index.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址