我使用CakePHP 2.5.5。我在这个目录中的项目:C:\ xampp \ htdocs \ vy \ cakephp-2.5.5。我的项目目录布局:
我已经创建了文件 C:\ xampp \ htdocs \ vy \ cakephp-2.5.5 \ app \ Model \ task.php (模型)内容:
<?php
class Task extends AppModel
{
var $name = 'Task';
}
?>
我已创建文件 C:\ xampp \ htdocs \ vy \ cakephp-2.5.5 \ app \ Controller \ TasksController.php (控制器)内容:
<?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
如何修复上述申请?谢谢!
答案 0 :(得分:3)
您所要做的就是仔细阅读错误信息:)
视图文件夹应为View\Tasks
(复数),而不是您目前拥有的View\Task
。
此外,您的模型文件名称应为Task.php
而不是task.php
。小心文件名中的区分大小写。如果您将文件移动到Linux服务器上,那么事情将在Windows上运行,因为它具有区分大小写的文件系统,您将收到错误。