Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

codeigniter base_url inside constants file

Currently I display images in the following way:

<img src="<?php echo base_url().USER_UPLOAD_URL.$post['userPhoto'] ?>" />

USER_UPLOAD_URL is defined inside application/config/constants.php.

define('USER_UPLOAD_URL', "uploads/user_uploads/");

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

like image 578
user1324762 Avatar asked Jan 21 '26 11:01

user1324762


1 Answers

constants.php loading before config.php, so you can't use $config['base_url'] from constants.php.

But you can do something like that:

constants.php:

define('BASE_URL', "http://mysite.com");
define('USER_UPLOAD_URL', BASE_URL."uploads/user_uploads/");

config.php

$config['base_url'] = BASE_URL;
like image 198
TheHorse Avatar answered Jan 23 '26 00:01

TheHorse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!