Welcome Guest, Not a member yet? Register   Sign In
Storing image locations using constants.

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; ?>

One question I have is can I use the $this->config->item('base_url') inside the constants.php file? Secondly, is it a good practice to store image names as constants in a constants file? Thanks for all of the help.

Did you try it?
Did it work?
If it did not give the expected result did you consult the "User Guide"?

No, it didn't work. I looked at the User Guide some, but I didn't see anything specifically that shows how to add your own constants. I'm still looking though.

Try this:

$base_url= $_SERVER['SERVER_NAME'];
  "<img src='http://" .$base_url .'  class='db_img' alt='#' />"
You could also take a look at creating an additional config.php file.

edit: problem due to square brackets, code got truncated so rewrote, now displays OK.

What got truncated on the $SERVER part of the code? One thing I've done so far is put the parts of the source that aren't a part of the base url into the database. But that is only a temporary fix. I did that for my menu but I'd rather it not be in the database. Thanks for the help so far.

Theme © iAndrew 2016 - Forum software by © MyBB