【问题标题】:Codeigniter cannot load helpersCodeigniter 无法加载帮助程序
【发布时间】:2018-01-14 02:45:06
【问题描述】:

我已经检查了所有配置文件,确保助手在系统/助手和应用程序/助手中以及其中一个中。我已经尝试过自动加载帮助程序,在我的控制器和视图中加载帮助程序,无论我遇到什么错误。

无法加载请求的文件:helpers/_helper.php

它就像我正在尝试加载一个空白助手,例如 $this->load->helper(''); 但我正在使用 $this->load->helper('url');

这是我的控制器来加载我的主页

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Pages extends CI_Controller {

  public function __construct(){
    parent::__construct();
    $this->load->helper('url');
  }

  public function index(){
    $this->load->view('templates/header');
    $this->load->view('home');
    $this->load->view('templates/footer');
  }
}

system/helpers/url_helper.php 和 application/helpers/url_helper.php 目前都存在并且根本没有被编辑过。

如果需要,我可以包含我的 autoload.php,但助手 Auto-load Helper Files 当前是 $autoload['helper'] = array();

【问题讨论】:

  • 默认情况下,APPPATH.'helpers/' 目录中不存在帮助文件。只是注意到你说它没有被编辑。它已经被某人设置在那里。尝试备份该文件,将其删除,然后再试一次,看看会发生什么。
  • 明确一点,您的意思是从目录中删除帮助文件,然后将它们放回原处吗?
  • 从应用程序目录中删除自定义帮助文件并尝试从系统目录中加载默认的帮助文件。
  • 我没有尝试加载任何自定义助手,只是尝试加载默认的 url 助手
  • 你可以在 github repo 中查看。 application/helpers默认没有帮助文件。

标签: php codeigniter helpers


【解决方案1】:

如果你需要覆盖 url helper

重命名文件

application/helpers/MY_URL_helper.php

application/helpers/MY_url_helper.php

【讨论】:

  • 我刚刚尝试过,但它不起作用。我尝试加载帮助程序的任何方式都无法加载请求的文件:helpers/_helper.php 即使重新安装 CI
  • @achill113 确保您的文件名是 Pages.php 而不是 pages.php
  • 我所有的控制器文件首字母大写
【解决方案2】:

复制url里面的整个路径,像这样,(wamp)

$this->load->helper('www/projectfoldername/applications/libraries/helpers/helperfile');

【讨论】:

  • 这对我来说绝对没有意义,但是当我把 $this->load->helper("url///");有效。对于每个斜线,都会显示一个字符。
猜你喜欢
  • 2012-01-27
  • 1970-01-01
  • 2016-02-09
  • 2012-01-31
  • 1970-01-01
  • 2010-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多