views:

369

answers:

2

Hi friends,

I use CodeIgniter, I'm happy with that, but I have a question.

I build my projects under /www/projectname/beta/... directory, so at my code, at many parts like including some images or css files or etc. I have to make ... src="/projectname/beta/... so when I complete the website, I need to edit so many pages to clear these /projectname/beta/ path and make it / for main root. or when I start new project with same base, first of all I need to edit these paths at all files.

now, how can I define a variable like

$projectbetapath = "/projectname/beta/";

and have access from everywhere, like global. where can I add such line, and how can I access this var from everywhere?

Thanks!! appreciate!

A: 

There are two answers to your question:

  1. Set your variables as array fields of $config in application/config/config.php and access them with $this->config->item('name');

  2. Use the URL-helper (Or $this->config->item('base_url')) to get the current base path whenever you have to type in a path.

The second answer will give you full flexibility, you'll only have to modify the base URL in config.php if the project moves.

christian studer
Setting it in config is a good option, but you should tell him how to create a constant if he wishes (like @Alix's answer) as well.
Mitchell McKenna
A: 

Why don't you add a constant in your index.php file?

define('BETA_PATH', '/beta');

When the site leaves the beta stage you just do:

define('BETA_PATH', '');
Alix Axel