CodeIgniter Forums
Custom Configuration File For Application - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Custom Configuration File For Application (/thread-15223.html)

Pages: 1 2


Custom Configuration File For Application - El Forum - 01-29-2009

[eluser]smatakajr[/eluser]
Hi,

I come from an Oscommerce background.. so im used to the whole application_top
require to set config directives. In making the change to CI which i must
say is pretty sweet and extendable im just getting used to the whole
3 step MVC format even though my prior code was indeed heavily encapsilated
anyway..

Is there a way in CI to include a application_top or config.php file that
will sit on the top GLOBALY so i dont have to load it in each model or controller?

I see the application/config/ and the autoload so im guessing my best bet is
to make a plugin or helper and add it to the autoload. Will this achive the same
effect as

include('config.php');
<?php ...code.. ?>

Sitewide?

Thanks alot
Rick


Custom Configuration File For Application - El Forum - 01-29-2009

[eluser]davidbehler[/eluser]
You can either use the existing config.php in your application/config folder or create a file of your own...let's say you call it custum_config.php...and add it to the config array in the autoload.php.

Both would lead to you having globally available config data.


Custom Configuration File For Application - El Forum - 01-29-2009

[eluser]smatakajr[/eluser]
Thanks Bro!

Rick


Custom Configuration File For Application - El Forum - 09-21-2009

[eluser]saidbakr[/eluser]
Hello,
I tried to make custom configuration file in application/config folder and then add it to autoload but it failed to globally propagate its values to the application. Typically I did the following two try:

1- Create a file called config1.php in the config folder and the following is its code:
Code:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* Custom Configurations:
*/
$config['fox_entry_words_count'] = 50;
The application returns an error message tell that the variable config is undefined.

2- I created the same file but I defined new array for cofiguartion and I called it config1. In this case the whole application is stopped and returned a message tell the following:
Quote:Your config1.php file does not appear to contain a valid configuration array.

How could I able to do custom configurations and what's its rules to be globbaly loaded. By the way, I loaded it in autoload.php
$autoload['config'] = array('config1');


Custom Configuration File For Application - El Forum - 09-22-2009

[eluser]davidbehler[/eluser]
Try this:
Code:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* Custom Configurations:
*/
$config = array();
$config['fox_entry_words_count'] = 50;



Custom Configuration File For Application - El Forum - 09-22-2009

[eluser]n0xie[/eluser]
Take a look here:
http://ellislab.com/codeigniter/user-guide/libraries/config.html


Custom Configuration File For Application - El Forum - 09-22-2009

[eluser]saidbakr[/eluser]
Hello,

Thank you all for your valuable help, specially, n0xie. I found that the way I used to get the configuration value was wrong!

I used : $config['the_index_of_conf'] and hence the application returns error tell that variable - config- is not defined. However, from the user guide, it is stated that to call the config value, we have to use the item method of the configuration object some thing like:
$this->config->item('the_index_of_config') and this will return the config value.


Custom Configuration File For Application - El Forum - 04-30-2010

[eluser]carvingCode[/eluser]
Having trouble using a custom config file. File is named 'app_config.php' and stored in the 'config' folder.

Get error: 'Your app_config.php file does not appear to contain a valid configuration array.'

Loading it:

Code:
$this->config->load('app_config');

Calling it:

Code:
$config = $this->config->item('cc_pagination_tags', 'app_config');

Code in app_config.php:

Code:
$cc_pagination_tags = array(
    'first_tag_open'    => ' | ',
    'first_tag_close'    => ' |',
    'last_tag_open'        => '| ',
    'last_tag_close'    => '| ',
    'num_tag_open'        => ' | ',
    'next_tag_open'        => ' | ',
    'next_tag_close'    => ' '
);

What am I missing?

TIA


Custom Configuration File For Application - El Forum - 04-30-2010

[eluser]InsiteFX[/eluser]
carvingCode,

Code:
$config['cc_pagination_tags'] = array(
    'first_tag_open'    => ' | ',
    'first_tag_close'    => ' |',
    'last_tag_open'        => '| ',
    'last_tag_close'    => '| ',
    'num_tag_open'        => ' | ',
    'next_tag_open'        => ' | ',
    'next_tag_close'    => ' '
);

Calling it:

Code:
$first_tag_open = $this->config->item('first_tag_open');

InsiteFX


Custom Configuration File For Application - El Forum - 04-30-2010

[eluser]carvingCode[/eluser]
Thanks for the help in structuring my code correctly. Much appreciated.

I was trying to reduce the amount of repetitive code in my functions... but I can't see where this will actually do that. End up with same number of statements and actually more characters.

Am I missing something?