Welcome Guest, Not a member yet? Register   Sign In

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.


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;

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.

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


Theme © iAndrew 2016 - Forum software by © MyBB