Welcome Guest, Not a member yet? Register   Sign In
How to set siteside constants

[eluser]omed habib[/eluser]

Where exactly can I define constants that can be used through the entire site (i.e. model, view and controller)?

I have constants I want to define that are server specific (for my various development environments and the live site) that I want to define to be used throughout the site.


config.php works for me.

[eluser]omed habib[/eluser]
I tried that... I can't figure out how exactly to set the constant. For example, doing this:

define("MAXSIZE", 100);

The constant 'MAXSIZE' isnt accessible. Any ideas?

mmm strange.

an example of how i use this is below:

define('HOME_PATH', '/home/mydomain/mydomain.local/');

$myVar = HOME_PATH;

This works perfectly for me.. but if you are having problems I have no idea Sad could be a server problems.. but it is strange.

I use a lot of constants in helper and plugin files and sometimes at the head of some controller files. I modified index.php to require a separate defines file just after APPPATH is defined in index.php.

| EXT  - The file extension.  Typically ".php"
| FCPATH - The full server path to THIS file
| SELF  - The name of THIS file (typically "index.php)
| BASEPATH - The full server path to the "system" folder
| APPPATH - The full server path to the "application" folder
define('EXT', '.'.pathinfo(__FILE__, PATHINFO_EXTENSION));
define('FCPATH', __FILE__);
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
define('BASEPATH', $system_folder.'/');

if (is_dir($application_folder))
define('APPPATH', $application_folder.'/');
if ($application_folder == '')
  $application_folder = 'applications';

define('APPPATH', $application_folder.'/');

// Include additional constants
$defines_file = 'includes/defines.php';
if (file_exists($defines_file))

Then you can add whatever constants you need quickly. In the above, I store the defines.php under includes/.

[eluser]omed habib[/eluser]
This was awesome... thanks guys... your posts were of definite help!

Coming from an (officially) former user of Symfomy, PHP Fusebox and CakePHP user, I have to say, I LOVE this framework!

Is it possible to define a constants just for some models, say, in case of a blog system, i want to some constants just for the post model, so i have a post_constants.php, if it's a comment model, i have a comment_constants.php...

Fantastic Esra! This was just what I was looking for. Clean, functional, and easy to understand for the next developer.


[eluser]Milos Dakic[/eluser]
Couldn't the constants.php file in the application/config folder be used for this or am I missing the point?

[quote author="Milos Dakic" date="1236056663"]Couldn't the constants.php file in the application/config folder be used for this or am I missing the point?[/quote]

Sure, but that's just too easy! Tongue

Theme © iAndrew 2016 - Forum software by © MyBB