貝殼 发表于 2012-5-12 15:12:52

Base_Url和urlHelper应用问题

大家好~

想请问大家几个问题:

View层调用Base_Url时,是否需要在Controller中添加一句:

$this->load->helper('url');

或是在View层加入一句:
<base href="<?php echo base_url() . 'application/views/';?>"/>
另外,如果我的项目网址是:
http://localhost/index.php/home

那么,印出base_url:
http://localhost/
请问,是正常的吗?

感谢大家回答了~

spt119 发表于 2012-5-12 22:33:41

你不加载$this->load->helper('url');无论在view还是controller,都不能使用base_url()。
base_url()和site_url(),是使用CI的两大神器,建议在config的autoload的helper中直接挂载。
楼主关于view的理解,感觉有点绕弯,建议多看看welcome这个例子。

貝殼 发表于 2012-5-13 12:23:07

spt119 发表于 2012-5-12 22:33 static/image/common/back.gif
你不加载$this->load->helper('url');无论在view还是controller,都不能使用base_url()。
base_url()和site ...

你好~

Welcome这个例子我看了很久,没有看出什么特殊之处,就Footer一个类似模版解析的代码。

能不能请您在说明下呢?

Hex 发表于 2012-5-13 17:00:10

貝殼 发表于 2012-5-13 12:23 static/image/common/back.gif
你好~

Welcome这个例子我看了很久,没有看出什么特殊之处,就Footer一个类似模版解析的代码。


看这个例子:http://codeigniter.org.cn/user_guide/tutorial/index.html
把他从头到尾好好研究下,你就入门了。

貝殼 发表于 2012-5-13 23:10:53

Hex 发表于 2012-5-13 17:00 static/image/common/back.gif
看这个例子:http://codeigniter.org.cn/user_guide/tutorial/index.html
把他从头到尾好好研究下,你就 ...

抽空去看看
页: [1]
查看完整版本: Base_Url和urlHelper应用问题