2016-08-03 69 views
0

所以,我嘗試了所有這些方法加載視圖,CI

$CI = CI_Controller::get_instance(); 

#or $CI =& get_instance(); 

$CI->load->view('pages/home'); 

但我沒有得到任何東西。如果我在

Unable to load the requested file: pages/homes.php一個錯誤,但是如果文件是正確的,我還是什麼也沒得到

還,我可以使用$CI->load->helper(some helper),並使用其功能和echo他們的結果。

對不起,如果我的問題是愚蠢的,但我搜索了很多,沒有找到問題,因爲我有。

+0

不好的方法。只需使用'$ this-> load-> view()' –

+0

什麼是工作流程?你爲什麼要從助手加載視圖? – Tpojka

+0

@Spartan我不能在助手中使用$ this,不是嗎? –

回答

0

您需要按照以下步驟:

  • 控制器

    class Stackoverflow extends CI_Controller{ 
    
        function __construct() { 
         parent::__construct(); 
    
         $this->load->helper('global_helper'); // load helper 
        } 
    
        function index(){ 
         call_view(); //calling of helper function 
        } 
    } 
    
  • 助手(global_helper.php)

    function call_view(){ 
        $CI = get_instance(); //creating instance of CI 
        $CI->load->view('view'); //loading of view.php 
    } 
    
  • 視圖(view.php)

    <html> 
        <head> 
         <title>View from Helper</title> 
        </head> 
        <body> 
         <p>This is text from helper</p> 
        </body> 
    </html> 
    
+0

Thx很多!我幾乎一樣,但問題出在我的控制器中。 –