我在 codeigniter 中有这样的目录结构:
Appsite
-website
-application
-images
当我访问 index.php 中的图像时,我使用了:<img src="http://localhost/Appsite/website/images/images.PNG"
其href为:<li class=""><a href="http://localhos/tAppsite/website/index.php/home/">Home</a></li>
我认为包括在内不是一个好的做法http://localhost
当访问代码点火器中的图像或库时。所以我尝试改变$config['base_url']
in config.php
to $config['base_url'] = "http://".$_SERVER["HTTP_HOST"]."/";
现在我更新我的图像源和其他库源,我删除本地主机和目录文件夹的名称:
<img src="images/images.PNG”>
<li class=""><a href= <?php echo base_url;?> /website/index.php/home/">Home</a></li>
但我收到错误。它说找不到对象。有人可以帮助我吗?
在配置.php中
$config['base_url'] = 'http://localhost/Appsite/website/';
$config['index_page'] = '';
# If online site
# $config['base_url'] = 'http://stackoverflow.com/';
In .htaccess
(应用程序文件夹之外)- 去除index.php
in URL
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|image|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
访问URL
<a href="<?php echo base_url();?>contollerName/methodName"> click here</a>
访问图像
<img src="<?php echo base_url();?>images/images.PNG”>
访问 CSS
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>assets/css/style.css"/>
To use base_url
从 autoload.php 加载 URL 助手
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)