我正在使用cakephp为数据库创建一个UI。我对cakephp是个新手,所以我有点卡住了。我已经成功地安装了cakephp,并将其连接到数据库。我已经创建了基于教程的模型,控制器和视图,但当我尝试加载这个页面时,localhost/app这是我得到的任何帮助都将非常感谢的错误。
这是我的控制器的路径: app/controller/OutagesController.php model: app/model/Outage.php view: app/View/Outages/index.ctp,我的代码也在下面,我是否加载了正确的URL?提前谢谢你,Tayo6。
enter code here
Error message:
Missing View
ERROR: THE VIEW FOR APPCONTROLLER::INDEX() WAS NOT FOUND.
ERROR: CONFIRM YOU HAVE CREATED THE FILE: /USERS/ESTHER.AGBAJI/SITES/CAKE/APP/VIEW/APP/INDEX.CTP
Notice: If you want to customize this error message, create app/View/Errors/missing_view.ctp
Stack Trace
CORE/Cake/View/View.php line 468 → View->_getViewFileName(null)
CORE/Cake/Controller/Controller.php line 948 → View->render(null, null)
CORE/Cake/Routing/Dispatcher.php line 194 → Controller->render()
CORE/Cake/Routing/Dispatcher.php line 162 → Dispatcher->_invoke(AppController, CakeRequest, CakeResponse)
APP/webroot/index.php line 110 → Dispatcher->dispatch(CakeRequest, CakeResponse)
APP/index.php line 19 → require(string)
MODEL CLASS (Outage.php)
<?php
class Outage extends AppModel {
var $name = 'Outages';
}
var $validate = array(
'id' => array(
'rule' => 'notEmpty'),
'start_date' => array(
'rule'=>'date'
'allowEmpty' => true),
'end_date' => array(
'allowEmpty' => true),
'application' => array(
'allowEmpty' => true),
'environment' => array(
'allowEmpty' => true),
'business_impact' => array(
'allowEmpty' => true),
'notified_by' => array(
'allowEmpty' => true),
'details' => array(
'allowEmpty' => true),
'severity' => array(
'rule' => 'notEmpty'),
'state' => array(
'allowEmpty' => true),
'resolved' => array(
'rule' => 'notEmpty')
'jira' => array(
'allowEmpty' => true)
);
?>
CONTROLLER CLASS (OutagesController.php)
<?php
class OutagesController extends AppController {
var $name = 'Outages';
var $helpers = array('Html', 'Ajax', 'Javascript');
function index() {
$this->set('outages', $this->Outage->find('all'));
}
function view($id = null)
{
$this->Outage->id = $id;
$this->set('outage', $this->Outage->read());
print_r($this->viewVars);
}
$this->Outages->set($this->request->data);
}
?>
VIEW (index.ctp)
<h2>Outages</h2>
<table>
<tr>
<th>Id</th>
<th>Start date</th>
<th>End date</th>
<th>Application</th>
<th>Environment</th>
<th>Business impact</th>
<th>Notified by</th>
<th>Details</th>
<th>Severity</th>
<th>State</th>
<th>Resolved</th>
<th>Jira</th>
</tr>
<?php foreach ($outages as $outage: ?>
<tr>
<td><?php> echo $outage['Outage']['id']?></td>
<td>
<?php> echo $html->link(($outage['Outage']['start_date'],
array('controller'=> 'outages', 'action'=> 'view', $outage['Outage']['id']));?>
</td>
<td><?php echo $outage['Outage']['end_date']; ?></td>
</tr>
<?php endforeach; ?>
</table> 非常感谢您的有用回复。我现在正在以正确的方式加载它,使用本地主机/停机,但我得到了这个错误消息:未找到请求的URL在此服务器上找不到/outages。我已经检查了我的文件,并确保它们在正确的位置。Tayo6
发布于 2013-07-16 08:45:19
很难从你的描述中准确地说出是哪个网址,但假设你让本地主机直接指向你的let应用程序,它应该是http://localhost/outages
通过使用localhost/app,您可以尝试获取'AppController‘的索引(虽然存在,但通常不会直接使用)。要为你的应用程序获取一个“主页”,你应该使用PagesController。
发布于 2013-07-16 11:33:54
一切似乎都是正确的,也许唯一的问题在于您试图访问的URL。
尝试使用包含/app、/lib、/vendors等的应用程序根文件夹名进行访问。
例如,http://localhost/testapp
要在浏览器上运行第一个页面,可以在app/Config/routes.php中进行设置
Router::connect('/', array('controller' => 'outages', 'action' => 'index'));https://stackoverflow.com/questions/17666114
复制相似问题