Welcome Guest, Not a member yet? Register   Sign In
Custom Configuration File For Application
#1

[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
#2

[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.
#3

[eluser]smatakajr[/eluser]
Thanks Bro!

Rick
#4

[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');
#5

[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;
#6

[eluser]n0xie[/eluser]
Take a look here:
http://ellislab.com/codeigniter/user-gui...onfig.html
#7

[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.
#8

[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
#9

[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
#10

[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?




Theme © iAndrew 2016 - Forum software by © MyBB