view里,大家是怎么安排image,css等路径问题的
用根路径时,不方便页面在dw里编辑用相对路径时,页面方便编辑了,但是运行时路径不对了
请大家教我,谢谢 我是用根路径,不方便编辑也没办法
<link href="<?=$this->config->item('base_url');?>css/style.css" rel="stylesheet" type="text/css" /> 这个好像没有特别好的办法,我一般就是用 base_url(),其实就是绝对路径,用相对路径肯定不行,因为所有路径都相对于 index.php 所在路径。 我是在和system同级目录下建立一个文件夹,然后在里面分别建立image、css、js三个文件夹来存放。
比如我建立的文件夹是www,那么结构就是下面这样
myweb
-system
-application
-cache
-codeigniter
-database
-www
-image
-css
-js
你用Rewrite的话,还要在.htaccess里面加入www这个目录名,然后在HTML中加入base标签
<base href="<?=$this->config->item('base_url')?>www/" />
接着你就可以像下面这样来取得css、image、js了
<link rel="stylesheet" type="text/css" href="css/mootree.css" />
<script src="js/mootree_packed.js" type="text/javascript"></script>
[ 本帖最后由 tiana 于 2008-2-15 10:25 编辑 ] 原帖由 shishirui 于 2008-2-15 10:20 发表 http://codeigniter.org.cn/forums/images/common/back.gif
我是用根路径,不方便编辑也没办法
css/style.css" rel="stylesheet" type="text/css" />
不要这么用,直接用 base_url() 谢谢楼上各位了:) 4楼的方法很聪明!
谢谢5楼提醒 原帖由 Hex 于 2008-2-15 10:26 发表 http://codeigniter.org.cn/forums/images/common/back.gif
不要这么用,直接用 base_url()
似乎不太行
<link href="<?php echo base_url();?>css/style.css" rel="stylesheet" type="text/css" />
Call to undefined function base_url() in D:\\htdocs\\ci\\system\\application\\views\\header.php on line 6
[ 本帖最后由 shishirui 于 2008-2-15 10:33 编辑 ] Controller里你没载入url_helper。 沧蓝说的对~
需要装载 URL 辅助函数。
页:
[1]
2