Codeigniter 4 - 在实时服务器上调用未定义函数 App\Controllers\base_url()
Codeigniter 4 - Call to undefined function App\Controllers\base_url() on live server
Codeigniter 4 base_url() 在本地主机上运行良好(即使使用像 http://192.168.0.2/ 这样的 IP 地址)
但是在将其上传到实时服务器时,我收到以下错误。
Call to undefined function App\Controllers\base_url()
我在 App\Config\App.php 文件中设置了 base_url 并尝试在 App\Config\BaseController.[=39= 中自动加载 url 助手] 文件如下图
public $baseURL = 'http://domainname.com/'; // App.php file
protected $helpers = ['url']; // BaseController.php file
我也试过在控制器函数中加载url_helper,比如
helper('url'); // my_controller.php file
我没有更改 .htaccess 文件中的任何内容。和ci4安装自带的一样。
知道是什么导致了这个问题吗?
.htaccess文件如下:
# Disable directory browsing
Options All -Indexes
# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------
# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# If you installed CodeIgniter in a subfolder, you will need to
# change the following line to match the subfolder you need.
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
# RewriteBase /
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ / [L,R=301]
# Rewrite "www.example.com -> example.com"
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to the front controller, index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L]
# Ensure Authorization header is passed along
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
# Disable server signature start
ServerSignature Off
# Disable server signature end
在 app.php 试试这个:
$main_root = "http://".$_SERVER['HTTP_HOST'];
$main_root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
public $baseURL = $main_root;
它将动态调用 url 而不是静态的 http 或 https。
事实证明我的系统文件已损坏,就像 TimBrownlaw 指出的那样。
导致此问题的主要且最有可能的问题是 url_helper 是否损坏。
但我通过重新下载和上传 Code Igniter 4 的核心文件解决了这个问题。
Codeigniter 4 base_url() 在本地主机上运行良好(即使使用像 http://192.168.0.2/ 这样的 IP 地址)
但是在将其上传到实时服务器时,我收到以下错误。
Call to undefined function App\Controllers\base_url()
我在 App\Config\App.php 文件中设置了 base_url 并尝试在 App\Config\BaseController.[=39= 中自动加载 url 助手] 文件如下图
public $baseURL = 'http://domainname.com/'; // App.php file
protected $helpers = ['url']; // BaseController.php file
我也试过在控制器函数中加载url_helper,比如
helper('url'); // my_controller.php file
我没有更改 .htaccess 文件中的任何内容。和ci4安装自带的一样。
知道是什么导致了这个问题吗?
.htaccess文件如下:
# Disable directory browsing
Options All -Indexes
# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------
# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# If you installed CodeIgniter in a subfolder, you will need to
# change the following line to match the subfolder you need.
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
# RewriteBase /
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ / [L,R=301]
# Rewrite "www.example.com -> example.com"
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to the front controller, index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L]
# Ensure Authorization header is passed along
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
# Disable server signature start
ServerSignature Off
# Disable server signature end
在 app.php 试试这个:
$main_root = "http://".$_SERVER['HTTP_HOST'];
$main_root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
public $baseURL = $main_root;
它将动态调用 url 而不是静态的 http 或 https。
事实证明我的系统文件已损坏,就像 TimBrownlaw 指出的那样。
导致此问题的主要且最有可能的问题是 url_helper 是否损坏。
但我通过重新下载和上传 Code Igniter 4 的核心文件解决了这个问题。