0

I'm using Codeigniter and right now I'm trying to define some constants to hold full paths to some folders like css, js, images, etc. and I've tried to define these constants in application/config/constants.php file like this:

define("PATH_TO_CSS_FOLDER", base_url("assets/css"));

but I've got this error:

Fatal error: Call to undefined function base_url() in D:\xampp\htdocs\demo\application\config\constants.php on line 44

so how can I define these constants without having to write the absolute path in the constants.php file like this:

define("PATH_TO_CSS_FOLDER", "http://my-website.com/assets/css");
3
  • How do you load the helper function? Probably you should use autoloading process as described here stackoverflow.com/questions/9009682/… Commented Dec 7, 2013 at 20:01
  • @james_bond I already load the url helper exactly like that mentioned in the approved answer you've referred to Commented Dec 7, 2013 at 20:11
  • Beside the right answer of "Rajeev Ranjan" which I've accepted, I also found this answer stackoverflow.com/a/13825685/458204 for another similar question, and I've found that it is really a great solution for the problem. Commented Dec 7, 2013 at 20:51

2 Answers 2

3

you can define rest of path in constant.php

define("PATH_TO_CSS_FOLDER","assets/css");

use it later in ohter places

<?php echo base_url(PATH_TO_CSS_FOLDER);?>

you might be knowing that constants loads first then any helper

Sign up to request clarification or add additional context in comments.

Comments

0

You have to load the url helper to access that function. Either you add

$this->load->helper('url');

somewhere in your controller, or you can put it into the application/config/autoload.php to be loaded automatically everywhere.

you have to use echo before base_url() function. otherwise it woudn't print the base url. like

echo base_url();

4 Comments

I already have url helper autoloaded, and that didn't fix the problem
Did u try site_url() ?
you have to use echo before base_url() function. otherwise it woudn't print the base url.
Yes I did, and it is the same as base_url() returns a fatal error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.