【问题标题】:CakePHP: Error: The view for TasksController::index() was not foundCakePHP:错误:未找到 TasksController::index() 的视图
【发布时间】:2014-10-25 08:46:22
【问题描述】:

我使用的是 CakePHP 2.5.5 。我在这个目录中的项目: C:\xampp\htdocs\vy\cakephp-2.5.5 。我的项目目录布局:



我已经创建了文件C:\xampp\htdocs\vy\cakephp-2.5.5\app\Model\task.phpModel强>)内容:

<?php

class Task extends AppModel
{
    var $name = 'Task';
}

?>



我已经创建了文件C:\xampp\htdocs\vy\cakephp-2.5.5\app\Controller\TasksController.phpController strong>) 内容:

<?php

class TasksController extends AppController
{
    var $name = 'Tasks';

    function index()
    {
        $this->set('tasks', $this->Task->find('all'));
    }
}

?>



我已经创建了文件C:\xampp\htdocs\vy\cakephp-2.5.5\app\View\Task\index.ctp查看) 内容:

<h2>Tasks</h2>
<?php if (empty($tasks)): ?>
    There are no tasks in this list
<?php else : ?>
    <table>
        <tr>
            <th>Title</th>
            <th>Status</th>
            <th>Created</th>
            <th>Modified</th>
            <th>Actions</th>
        </tr>
        <?php foreach ($tasks as $task): ?>
            <tr>
                <td>
                    <?php echo $task['Task']['title'] ?>
                </td>
                <td>
                    <?php
                    if ($task['Task']['done']) echo "Done";
                    else echo "Pending";
                    ?>
                </td>
                <td>
                    <?php echo $task['Task']['created'] ?>
                </td>
                <td>
                    <?php if ($task['Task']['modified']) ?>
                </td>
                <td>
                    <!-- actions on tasks will be added later -->
                </td>
            </tr>
        <?php endforeach; ?>
    </table>
<?php endif; ?>



运行程序时出现错误:

Missing View
Error: The view for TasksController::index() was not found.

Error: Confirm you have created the file: C:\xampp\htdocs\vy\cakephp-2.5.5\app\View\Tasks\index.ctp

Notice: If you want to customize this error message, create app\View\Errors\missing_view.ctp


如何修复上述应用程序?谢谢!

【问题讨论】:

    标签: php cakephp


    【解决方案1】:

    您所要做的就是仔细阅读错误消息:)

    视图文件夹应该是View\Tasks(复数),而不是您当前的View\Task

    您的模型文件名也应该是Task.php 而不是task.php。注意文件名的大小写敏感。如果您将文件移动到 linux 服务器,则在 Windows 上一切正常,但您会收到错误,因为它具有区分大小写的文件系统。

    【讨论】:

    • 当我按照您的指示重命名 task.php --> Task.php Error: Notice (8): Undefined index: Tasks [APP\View\Tasks\index.ctp, line 16] 我也必须更改代码。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-20
    • 2013-01-17
    • 2012-04-29
    • 2017-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多