【问题标题】:link_tag() not working in codeIgniterlink_tag() 在 codeIgniter 中不起作用
【发布时间】:2015-06-15 16:47:41
【问题描述】:

我是 codeIgniter 的新手,我创建了一个简单的模块。 在我的代码中,我创建了一个家庭控制器,并且 Home.php 遵循

 public function index() {
    $data['title'] = 'Welcome';
    $this->load->view('home/index', $data);
 }

我在 view/home/index.php 中创建了一个视图文件,代码如下

link_tag('css/style.css');
echo $title;

当我使用 link_tag() 时,它显示以下错误消息

致命错误:在第 2 行调用 C:\xampp\htdocs\code\application\views\home\index.php 中未定义的函数 link_tag()

请帮助我解决这个问题。

【问题讨论】:

    标签: codeigniter


    【解决方案1】:

    你首先需要加载这个助手:$this->load->helper('html');

    要使link_tag() 工作,您需要像$this->load->helper('html'); 那样加载HTML 帮助程序

    所以在你的控制器代码中,我会这样添加:

    public function index() {
        $this->load->helper('html');
        $data['title'] = 'Welcome';
        $this->load->view('home/index', $data);
     }
    

    【讨论】:

    • 请您解释一下。这样我就可以试试了。我可以把这段代码放在哪里。?
    【解决方案2】:

    要在每个函数中添加 $this->load->helper('html'),我们可以在 application/config/autoload.php 文件中使用 $autoload['helper'] = array('html');

    【讨论】:

      【解决方案3】:

      要使用link_tag(),您需要加载html helper

      你可以使用

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

      那么你的代码是这样的

      public function index() {
      $this->load->helper('html');
      $data['title'] = 'Welcome';
      $this->load->view('home/index', $data);
      

      }

      【讨论】:

        【解决方案4】:

        你首先需要加载这个助手:

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

        或自动加载 HTML 帮助程序

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

        那么你的代码是这样的

        public function index() {
            $this->load->helper('html');// don't need if you autoload the html helper
            $data['title'] = 'Welcome';
            $this->load->view('home/index', $data);
         }
        

        【讨论】:

          猜你喜欢
          • 2012-12-16
          • 2014-12-23
          • 2018-04-23
          • 2021-03-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多