【问题标题】:CodeIgniter helper not loadingCodeIgniter 助手未加载
【发布时间】:2012-12-30 08:00:57
【问题描述】:

我试图使用这个助手来创建一个国家下拉列表。(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

【问题讨论】:

  • 你把country_helper.php放在哪里?
  • @pktangyue in /application/helpers
  • 我试过了,效果很好。你的加载系统助手能正确吗?
  • 我可以自动加载它们,但是当我使用$this->load->helper('country_helper'); 时似乎没有加载它
  • 你在__construct()中添加parent::__construct()

标签: codeigniter helper


【解决方案1】:

使用: $this->load->helper('country');

不是: $this->load->helper('country_helper');

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:
      class Welcome extends CI_Controller {
          public function __construct()
          {   
              parent::__construct();
              $this->load->helper('country_helper');
              echo country_dropdown();
          }   
          public function index()
          {
          }    
      }
      

      我试过这段代码,它工作正常。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-20
      • 2011-01-12
      • 2011-05-25
      • 1970-01-01
      • 1970-01-01
      • 2013-09-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多