2014-03-27 111 views
0

我必須在控制器文件夾中名稱about.php的控制器。現在在視圖文件夾中我有一個名爲about.php的視圖。在index.php視圖中,我想通過鏈接調用該視圖,但它不會調用我對Codeignitor的新功能。麻煩呼叫視圖

這是我的index.php調用代碼

<a href="<?php echo base_url();?>About/about">About Us</a> 

這是控制器的文件夾我的控制器代碼about.php。

class About extends CI_Controller { 

    function index(){ 

     $this->load->view('about'); 
    } 

} 

回答

1

你的觀點應該被稱爲about.php,並在views文件夾中。

您的控制器然後調用此視圖(正確)稱爲about

因此正確的鏈接,這種觀點是如下:

<a href="<?= site_url('about'); ?>">About Us</a> 

你可以閱讀有關base_urlsite_urlhere之間的差異。

+0

謝謝侑先生是工作正常,但我的鏈接是這樣的「http://localhost/CodeIgniter/index.php/about」我們可以刪除.PHP或索引。從這個鏈接的PHP – Nasir

+0

是的,你可以做一個簡單的改變你的.htaccess文件。這是在CodeIgniter文檔中:http://ellislab.com/codeigniter/user-guide/general/urls.html – Tom

+0

先生什麼是index.php這裏可以解釋一下 – Nasir

0

試試這個:

<a href="<?php echo base_url();?>index.php/about">About Us</a> 
+0

這裏是index.php – Nasir

+0

默認情況下,index.php文件將包含在您的URL中。您可以通過使用帶有一些簡單規則的.htaccess文件輕鬆刪除此文件。 – Vasu

+0

文檔:http://ellislab.com/codeigniter/user-guide/general/urls.html – Vasu