2012-03-02 51 views
0

我route.php文件沮喪笨的配置運行一個簡單的程序

$route['default_controller'] = "pxml"; 
$route['pxml/(:any)']="xml/pxml"; 
$route['404_override'] = ''; 

我的index.php文件

<!DOCTYPE html> 
<html> 
    <head> 
      <title>Reading/Writing XML</title> 
    </head> 
    <body> 
     Welcome to reading/writing XML! 
     <a href="loadXML">Display</a> 
    </body> 
</html> 

我的課Pxml.php文件

class PXml extends CI_Controller 
{ 
    private $pFunc; 
    public function __construct() 
    { 
     parent::__construct(); 
     $this->pFunc=new PFunc(); 
    } 
    public function index() 
    { 
     if(!file_exists('application/views/xml/index.php')) 
     { 
      show_404(); 
     } 
     $this->load->view('xml/index'); 
    } 
    public function loadXML() 
    { 
     if(!file_exists('application/views/xml/books.php')) 
     { 
      show_404(); 
     } 
     else 
     { 
      if(!file_exists('application/controllers/books.xml')) 
      { 
       show_404(); 
      } 
      $data['xml_data']=$this->pFunc->ReadXML('books.xml'); 
      if($data['xml_data']!=null) 
      { 
       $this->load->view('xml/books',$data); 
      } 
      else 
      { 
       echo "Fail to load XML file"; 
      } 
     } 
    } 
} 


?> 

我的書.php

<?php  
    echo <<<EOF 
    <table> 
     <tr> 
      <th>Title</th> 
      <th>Author</th> 
      <th>Publisher</th> 
      <th>Price at Amazon.com</th> 
      <th>ISBN</th> 
     </tr> 
    EOF; 
    foreach($xml_data as $book) 
    { 
     echo <<<EOF 
     <tr> 
      <td>{$book->title}</td> 
      <td>{$book->author}</td> 
      <td>{$book->publisher}</td> 
      <td>{$book->amazon_price}</td> 
      <td>{$book['isbn']}</td> 
     </tr> 
     EOF; 
    } 
    echo '</table>'; 
?> 

我可以達到索引,但當我按顯示鏈接時,我得到了404錯誤。

此外,我在控制器中創建了一個名爲xml的子文件夾來存儲pxml文件。和一個名爲xml的子文件夾來存儲所有視圖文件。任何幫助表示讚賞。

+0

你有什麼試過?你是否100%確定這些文件存在?你有沒有嘗試在代碼中的不同位置放置一些回聲,以查看它失敗的位置? – joakimdahlstrom 2012-03-02 17:29:38

+0

您是否嘗試在loadXML控制器中爲file_exists取出所有條件並僅輸出字符串以查看該方法是否被調用? – koosa 2012-03-02 17:29:52

+0

在瀏覽器中嘗試'http:// example.com/index.php/pxml/loadXML'。 – hakre 2012-03-02 17:47:35

回答

0

CI要求所有文件名都是小寫。

變化

Pxml.php 

pxml.php 
0

嘗試更改鏈接,以顯示對這樣的事情。

<a href="<?php echo site_url('pxml/loadxml')?>">Display</a> 

您是否也驗證過CI是否因爲無法找到視圖而拋出404或者它無法找到控制器本身?