本文介绍了codeigniter base_url里面的常量文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前我以以下方式显示图片:
Currently I display images in the following way:
<img src="<?php echo base_url().USER_UPLOAD_URL.$post['userPhoto'] ?>" />
USER_UPLOAD_URL在application / config / constants.php中定义。
USER_UPLOAD_URL is defined inside application/config/constants.php.
define('USER_UPLOAD_URL', "uploads/user_uploads/");
有什么办法在constants.php里包含base_url这样我就不需要每次都写base_url()里面的视图。是否有其他方法?
Is there any way to include base_url() inside constants.php? In this way I wouldn't need to write each time base_url() inside view. Is there any alternative approach?
tnx
推荐答案
constants.php在config.php之前加载,因此不能使用constants.php中的 $ config ['base_url']
。
constants.php loading before config.php, so you can't use $config['base_url']
from constants.php.
但您可以这样做:
constants.php :
define('BASE_URL', "http://mysite.com");
define('USER_UPLOAD_URL', BASE_URL."uploads/user_uploads/");
config.php
$config['base_url'] = BASE_URL;
这篇关于codeigniter base_url里面的常量文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!