2016-08-03 110 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很多!我几乎一样,但问题出在我的控制器中。 –