• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Constant

#1
[eluser]Shella[/eluser]
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

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

and I get the valur back in a controller file with:
Code:
$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.

Thanks!

#2
[eluser]InsiteFX[/eluser]
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.
Code:
define('ABSOLUTE_PATH', "/htdocs/public/www/somefolder");

$data['absolute_path'] = ABSOLUTE_PATH;

#3
[eluser]CroNiX[/eluser]
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.

#4
[eluser]Shella[/eluser]
Many thanks for both replies.
I will make treasure with that.

Shella


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.