我想在配置文件中定义另一个网址
codeigniter默认基本网址
$config['base_url'] = 'www.domain.com/backend';
我定义了另一个网址
$config['front_url'] = 'www.domain.com/frontend';
当我调用front_url(); 它给出了错误 调用未定义的函数front_url()
答案 0 :(得分:2)
base_url()是一个函数,你可以在url_helper.php文件中找到这个函数(你必须加载帮助才能使用它)。
如果要将front_url()用作函数,则必须在自己的帮助器中创建自己的函数,如base_url():
public function front_url($uri = '')
{
// If used in helper, you must get instance
$ci &= get_instance();
$front_url = $ci->config->item('front_url');
return $front_url . ltrim($uri, '/');
}
答案 1 :(得分:0)
你可以使用风格。我希望它能为你充分使用
如果(isset($ _ SERVER [ 'HTTP_HOST'])) { $ site_url = isset($ _ SERVER ['HTTPS'])&& strtolower($ _ SERVER ['HTTPS'])=='on'? 'https':'http'; $ site_url。='://'。 $ _SERVER [ 'HTTP_HOST']; $ site_url。= str_replace(basename($ _ SERVER ['SCRIPT_NAME']),'',$ _SERVER ['SCRIPT_NAME']);
// Base URI (It's different to base URL!)
$site_uri = parse_url($base_url, PHP_URL_PATH);
if(substr($site_uri, 0, 1) != '/') $site_uri = '/'.$site_uri;
if(substr($site_uri, -1, 1) != '/') $site_uri .= '/';
}
else
{
$site_url = 'http://static_location/';
$site_uri = '/';
}
// Define these values to be used later on
define('BASE_URL', $site_url);
define('BASE_URI', $site_uri);
define('APPPATH_URI', BASE_URI.APPPATH);
// We dont need these variables any more
unset($site_uri, $site_url);
$config['base_url'] = BASE_URL;
答案 2 :(得分:0)
base_url() in CI function which returns your site base URL, as specified in your config file.
First you define a base_url() in config.php
$config['base_url'] = 'www.domain.com/backend';
then define your custome url path
define('front_url',$base_url.'front_url');
Now you can access this in controller or view or helper like this
$image_path = $front_url.'/image';