从帮助程序加载视图,CI

时间:2016-08-03 19:02:18

标签: php codeigniter-3

所以,我尝试了所有这些方法

- name: Fix 'support_tools' permissions
  file: path={{ item }} owner=abc group=abc mode=0775 
  with_items:
    - /dir/tools/a.sh
    - /dir/tools/b.sh
    - /dir/tools/c.sh

但我什么都没得到。如果我在

中犯了错误

$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)他们的结果。

很抱歉,如果我的问题是愚蠢的,但我搜索了很多,并没有找到问题,因为我有。

1 个答案:

答案 0 :(得分: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>