base_url()函数在错误页面上不起作用。即使自动加载后 [英] base_url() function won't work on error pages. Even after autoloading

查看:141
本文介绍了base_url()函数在错误页面上不起作用。即使自动加载后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个漂亮的错误页面。为此,我需要获取一些CSS和JS文件。但是由于某些奇怪的原因,使用 base_url()不能在error_pages上使用。我当然可以只使用 href = / css / style.css 并告诉它从根文件夹中获取它。但是,很可能将网站放置在与根文件夹不同的文件夹中。因此,不能使用 /

I want to have nice good looking error pages. For this I need to get some CSS and JS files. But for some odd reason using base_url() does not work on the error_pages. I could of course just use href="/css/style.css" and tell it to get it from the root folder. But the website could very well be put in a different folder than the root folder. So using the / is not an option.

所以我现在的问题是为什么不 base_url( )在错误页面上工作?我已经自动加载了它,所以它不应该工作吗?

So my question now is why doesn't base_url() work on an error page? I have autoloaded it so shouldn't it be working?

这是我尝试从视图中的error_404页面获取base_url()时尝试的。

This is what I tried when I was trying to get the base_url() from the error_404 page in the view.

在我的autoload.php文件中,我包括了辅助程序 url

In my autoload.php I have included the helper url

$autoload['helper'] = array('url', 'form');

在我的error_404页面(application / views / errors / html / error_404.php)中,我像这样回显base_url :

And in my error_404 page (application/views/errors/html/error_404.php) I am echoing the base_url like so:

<?php echo base_url(); ?>

这是我遇到的错误:

An uncaught Exception was encountered

Type: Error

Message: Call to undefined function base_url()

Filename: /usr/local/www/example.com/application/views/errors/html/error_404.php

Line Number: 37

Backtrace:

    File: /usr/local/www/example.com/index.php
    Line: 315
    Function: require_once

我不想在 system 文件夹中进行任何更改,因为我不想在每次更新Codeigniter文件夹时都重做该过程。

I'd rather not make any changes in the system folder since I don't want to redo the process every time I update Codeigniter folder.

系统:


Codeigniter 3.0.6

Codeigniter 3.0.6

PHP 7.0.8

PHP 7.0.8

Nginx 1.11.1

Nginx 1.11.1

更新:
我想在每个错误页面上调用base_url (db,404,常规,php等)。

UPDATE: I'd like to call base_url on every error page (db, 404, general, php, etc.).

推荐答案

自动加载器无法正常工作,因为自动加载器会加载库<强> 之后,错误检查完成。如果出现诸如未找到 404之类的错误,它将在不加载自动装带器的情况下查看自定义错误页面。

The autoloader does not work because the autoloader loads the libraries after the error checks are finished. If there are errors like a 404 not found it will view the custom error page without loading the autoloader.

到在自定义页面上获取base_url,您需要在自定义错误页面中添加以下内容:

To get your base_url on a custom page you would need to add the following in your custom error page:

$base_url = load_class('Config')->config['base_url'];

来自:
http://forum.codeigniter.com/thread-65968-post-335822.html#pid335822

这篇关于base_url()函数在错误页面上不起作用。即使自动加载后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆