codeigniter 新助手未加载
codeigniter new helper is not load
我尝试加载自定义助手,但它无法加载并生成这样的错误
An Error Was Encountered
无法加载请求的文件:helpers/getdata_helper.php
我的助手存储在
Application/helper/getdata.php
我的控制器是
class home extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('home_model');
$this->load->helper(array('url','form','language','string'));
$this->load->helper('getdata');
//$this->EE->load->helper('menu_load');
}
public function index()
{
$menu['menu']=$this->home_model->get_menu();
$menu['print_menu']=$this->echoMenu($menu['menu']);
$data['latest']=$this->home_model->get_latest_product();
$this->load->view('header_1',$menu);
$this->load->view('index',$data);
$this->load->view('footer');
}
应该不会报错。无论如何尝试像这样自动加载它:
$autoload['helper'] = array('getdata');
让我们看看 des doc 是怎么说的:
Loading a helper file is quite simple using the following function:
$this->load->helper('name');
Where name is the file name of the helper, without the .php file
extension or the "helper" part.
For example, to load the URL Helper file, which is named
url_helper.php, you would do this: $this->load->helper('url');
它清楚地表明 CI 将查找名为 xxx_helper.php 的文件。
在您的情况下,当加载 getdata
时,CI 将在 application/helpers
中查找 getdata_helper.php
.
您只需重命名文件即可使其正常工作。
我尝试加载自定义助手,但它无法加载并生成这样的错误
An Error Was Encountered
无法加载请求的文件:helpers/getdata_helper.php
我的助手存储在
Application/helper/getdata.php
我的控制器是
class home extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('home_model');
$this->load->helper(array('url','form','language','string'));
$this->load->helper('getdata');
//$this->EE->load->helper('menu_load');
}
public function index()
{
$menu['menu']=$this->home_model->get_menu();
$menu['print_menu']=$this->echoMenu($menu['menu']);
$data['latest']=$this->home_model->get_latest_product();
$this->load->view('header_1',$menu);
$this->load->view('index',$data);
$this->load->view('footer');
}
应该不会报错。无论如何尝试像这样自动加载它:
$autoload['helper'] = array('getdata');
让我们看看 des doc 是怎么说的:
Loading a helper file is quite simple using the following function: $this->load->helper('name');
Where name is the file name of the helper, without the .php file extension or the "helper" part.
For example, to load the URL Helper file, which is named url_helper.php, you would do this: $this->load->helper('url');
它清楚地表明 CI 将查找名为 xxx_helper.php 的文件。
在您的情况下,当加载 getdata
时,CI 将在 application/helpers
中查找 getdata_helper.php
.
您只需重命名文件即可使其正常工作。