如何在 CodeIgniter 2.* 中获取基本 url [英] How to get base url in CodeIgniter 2.*
本文介绍了如何在 CodeIgniter 2.* 中获取基本 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 config.php 中
In config.php
$config['base_url'] = 'http://localhost/codeigniter/';
在视图中
<link rel="stylesheet" href="<?php base_url(); ?>css/default.css" type="text/css" />
<代码>=>错误:调用未定义的函数 base_url(); 帮帮我
推荐答案
要使用base_url()
(简写),你必须先加载URL Helper
>
To use base_url()
(shorthand), you have to load the URL Helper
first
$this->load->helper('url');
或者你可以通过改变application/config/autoload.php
或者就用
$this->config->base_url();
同样适用于 site_url()
.
我还可以看到您缺少 echo
(虽然这不是您当前的问题),请使用下面的代码解决问题
Also I can see you are missing echo
(though its not your current problem), use the code below to solve the problem
<link rel="stylesheet" href="<?php echo base_url(); ?>css/default.css" type="text/css" />
这篇关于如何在 CodeIgniter 2.* 中获取基本 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文