CodeIgniter Forums
Constant - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: Constant (/showthread.php?tid=53887)

Constant - El Forum - 08-13-2012

Hi guys,
today i'm looking for suggestion!

Actually I'm working on a site that need to identify some constant.
I chased around with uncle Google but posts are old and different people said different solutions.

The question is quite simple. Which is the best way to use connstant variables with codeigniter (2.1.2)

Personally I set up constant like this is config/config.php

define('absolute_path', "/htdocs/public/www/somefolder");

and I get the valur back in a controller file with:
$data['absolute_path'] = absolute_path;
$this->load->view('destination_viewfile', $data); // to pass the value...

It just work but seem to me such tricky and remind me a workaround more then a code stuff...

Your suggestions are veeeery appreciated.


Constant - El Forum - 08-13-2012

The right place to place them is in ./application/config/constants.php at the bottom.

Also when you define a constant it should be uppercase like this.
define('ABSOLUTE_PATH', "/htdocs/public/www/somefolder");

$data['absolute_path'] = ABSOLUTE_PATH;

Constant - El Forum - 08-13-2012

If you globally define() something, there isn't really a need to assign it to yet another variable and then pass it to a view. Just use it directly in the view.

Constant - El Forum - 08-16-2012

Many thanks for both replies.
I will make treasure with that.