开发者

How to make constants in CodeIgniter for images?

I want to use the constants.php file to store common image locations. I have a menu and each item has an image of it’s own, and currently for each image in the view, I have:

<?php echo $this->config->item(‘base_url’); ?>/images/database.png”>

Or whatever the filename is. What I want to do is store a constant “DB_IMG” in this instance, and simply be able to say in my view:

<?php echo DB_IMG; ?>

I know that I can't put:

$this->config->item('base_url')

in the constants file (I tried it, it errored out) and I tried:

$config('base_url')

which said it wasn't defined. Here's what I'd like to put in my constants file (even though I know this doesn't work) so if you could help me, I'd appreciate it:开发者_开发百科

define('DB_IMG',$this->config->item('base_url').'/images/database.png');

Thanks.


try this in constants.php

require APPPATH . 'config/config' . EXT;

define(BASE_URL, $config['base_url']);
define(DB_IMG, $config['base_url'] . '/images/database.png');  

unset($config);


Because constants.php is in the config directory it doesn't have access to config items because config.php hasn't been loaded yet. I think you'll need to put the full URL in there or else use native PHP functions to get the base URL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜