• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating config variable file

#1
[eluser]bigdaddysheikh[/eluser]
Hey guys,

I keep running into the problem of "undefined variables". It is driving me bonkers. First I declared them in each class and sub fucntion. This lead to too many same lines in different controllers. I tried making a config file by setting the variable $data and arrays inside $data. That did not help.

So for example, I will have an error message or message i want to display, or generic html messages.

$data["error"]
$data["title"]
$data["footer"]

How can I set these variables? Which file would they go in and how will this file be accessed so my website will not show any of those udefined errors again.

Thank you in advance.

#2
[eluser]Colin Williams[/eluser]
Did you miss the Loader class documentation in the user guide? It details the many ways to make data available in your View files. Also, there is clear documentation on how to add and use your own config files, but here's the basic rundown.

Add the file application/config/my_config.php

Code:
$config['an_item'] = 'A value';
$config['another_item'] = 'Another value';
// We must add items to the $config array, not our own made-up variable.

Then to get at these items, we must first load this config file. One way is with the Loader class:

Code:
$this->load->config('my_config');
// See? It's just our config filename without the '.php' extension
// Now, lets use our config items
$value = $this->config->item('an_item');
$value2 = $this->config->item('another_item');

#3
[eluser]bluepicaso[/eluser]
thank you


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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