2013-07-16 55 views
0

我正在使用cakephp为数据库创建UI。我对cakephp很新,所以我有点卡住了。我已成功安装cakephp,将其连接到数据库。我已经创建了基于教程的模型,控制器和视图,但是当我尝试加载此页面本地主机/应用程序,这是我得到的错误 任何帮助将不胜感激。Cakephp-缺少视图错误

这是我的控制器的路径:app/controller/OutagesController.php模型:app/model/Outage.php查看: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 /中断。我已经通过我的档案,并确保他们在正确的地方。 Tayo6

+0

非常感谢你对你有用的反应。我现在使用正确的方式加载它,使用http:// localhost/outages,但我收到此错误消息: 未找到 在此服务器上未找到请求的URL /中断。 我已经通过我的文件,并确保他们在正确的地方。 Tayo6 – user2585015

+0

对于那些从搜索来到这里的人。在我的例子'beforeFilter()'引起这个问题。有关更多信息,请参阅http://stackoverflow.com/questions/16921021/cakephp-plugin-throws-missing-view-error-but-view-file-exits/40872968#40872968。 –

回答

1

这是很难从你的描述告诉到底哪个URL,但假设你让本地主机直接指向你的web应用,它应该是http://localhost/outages

通过使用本地主机/应用程序,你正在试图获得的索引'AppController'(它存在,但通常不直接使用)。要为您的应用获取“主页”页面,您应该使用PagesController。

0

一切似乎都是正确的,也许只有问题出在您尝试访问的URL中。

尝试与包含应用程序的根文件夹名称/应用程序,/ lib下,商/供应商等

对于例如访问http://localhost/testapp

第一页要在浏览器中运行,可以使该设置在app/Config/routes.php

Router::connect('/', array('controller' => 'outages', 'action' => 'index'));