CodeIgniter 帮助程序未加载

问题描述 投票:0回答:4

我试图使用这个助手创建一个国家/地区下拉列表。(https://github.com/EllisLab/CodeIgniter/wiki/helper-dropdown-country-code)

我创建了一个名为

country_helper.php
的文件,其中包含帮助程序代码,在我的控制器中,我使用
$this->load->helper('country_helper');

加载该帮助程序

但是当使用

country_dropdown();
时,我收到以下错误:

Call to undefined function country_dropdown() in /Users/wouter/Sites/socialagent.me/application/controllers/user.php on line 299
codeigniter helper
4个回答
2
投票

您需要更好地设置全局帮助程序功能。找到文件 application/config/autoload.php 并设置

$autoload['helper'] = array('country');

1
投票

使用:

$this->load->helper('country');

不是:

$this->load->helper('country_helper');


0
投票
class Welcome extends CI_Controller {
    public function __construct()
    {   
        parent::__construct();
        $this->load->helper('country_helper');
        echo country_dropdown();
    }   
    public function index()
    {
    }    
}

我尝试了这段代码,效果很好。


0
投票

您唯一需要做的就是将以下内容添加到您的composer.json 文件中。例如:在“require”之后:{ }

"autoload": {
    "files": [
        "application/helpers/<YOUR_HELPER_FILE_NAME>.php"
    ]
},

这将自动加载您的帮助文件。您不必手动加载它。

© www.soinside.com 2019 - 2024. All rights reserved.