在 codeigniter 中设置基本 url [英] Set up the base url in codeigniter

查看:32
本文介绍了在 codeigniter 中设置基本 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在代码点火器中有这样的目录结构:

I have the directory structure like this in code igniter:

 Appsite
    -website
       -application
        -images

当我访问 index.php 中的图像时,我使用了:<img src="http://localhost/Appsite/website/images/images.PNG"

When I accessing the image in index.php I used: <img src="http://localhost/Appsite/website/images/images.PNG"

href 是:<li class=""><a href="http://localhos/tAppsite/website/index.php/home/">首页</a></li>

我认为在代码点火器中访问图像或库时包含 http://localhost 不是一个好习惯.所以我尝试更改 config.php 中的 $config['base_url']$config['base_url'] = "http://".$_SERVER["HTTP_HOST"]."/";

I think it is not a good practice to include the http://localhost when accessing the images or libraries in code igniter. So I tried to change the $config['base_url'] in config.php to $config['base_url'] = "http://".$_SERVER["HTTP_HOST"]."/";

现在我更新了我的图像源和其他库源,我删除了本地主机和目录文件夹的名称:

And now I update my image source and other library source I remove the localhost and the name of my directory folder:

<li class=""><a href= <?php echo base_url;?>/website/index.php/home/">首页</a></li>

但是我遇到了错误.它说找不到对象.有人可以帮我吗?

But I get errors. it says object not found. Can some help me?

推荐答案

在 Config.php

$config['base_url'] = 'http://localhost/Appsite/website/';
$config['index_page'] = '';

# If online site
# $config['base_url'] = 'http://stackoverflow.com/';

.htaccess(应用程序文件夹外) - 删除 URL 中的 index.php

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]

<小时>

访问网址

<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"/>

<小时>

使用 base_url 从 autoload.php 加载 URL 助手


To use base_url load URL helper from autoload.php

这篇关于在 codeigniter 中设置基本 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆