[answered] is this the correct way to get info from config file ? |
[eluser]jozeunico[/eluser]
I am creating my own library, but I have a couple of doubts, the most important is how can I retrieve the values (inside the library to display them) from the config file. I did something like this: I have my config file "mylibrary.php" and of course my library "Mylibrary.php" My library: Code: class Mylibrary { My config file just have this: Code: config['title']='My title'; In a controller a load the library and call the funcion "showMessage" and it works, my doubt it's if it's correct use this: Code: $this->CI=& get_instance(); To set values from a config file and display them (or use them for any operation). Thanks. p.s. I saw this in the FreakAuth library just if you are wondering.
[eluser]omar-303[/eluser]
I think you should load the configuration file first Code: $this->CI =& get_instance();
[eluser]Wilbur Himself[/eluser]
config_item('item_key') The Config library is the preferred way of accessing configuration information, however config_item() can be used to retrieve single keys. See Config library documentation for more information. http://ellislab.com/codeigniter/user-guide/general/common_functions.html
[eluser]Thorpe Obazee[/eluser]
[quote author="jozeunico" date="1244005441"] Code: $this->CI=& get_instance(); To set values from a config file and display them (or use them for any operation). Thanks. p.s. I saw this in the FreakAuth library just if you are wondering.[/quote] I believe it is. Of course the config file should have been loaded already.
[eluser]jozeunico[/eluser]
[quote author="omar-303" date="1244007123"]I think you should load the configuration file first Code: $this->CI =& get_instance(); Quote:I believe it is. Of course the config file should have been loaded already. I'm sorry y forgot to say it, I've already loaded the config using de /config/autoload.php onfig_item(‘item_key’) Quote:The Config library is the preferred way of accessing configuration information, however config_item() can be used to retrieve single keys. See Config library documentation for more information.I didn't understand the doc (my english isn't good), thats why the post. Thanks anyone and if somebody can explain these lines (for dummys) I'll thank you. [code] $this->CI =& get_instance(); $this->CI->load->config('mylibrary'); [/code
[eluser]omar-303[/eluser]
Code: $this->CI =& get_instance(); Code: $this->CI->load->config('mylibrary');
[eluser]jozeunico[/eluser]
[quote author="omar-303" date="1244076278"] Code: $this->CI =& get_instance(); Code: $this->CI->load->config('mylibrary'); Thank you, I guess I got it, but still get confused because it use a lot of "levels" or the symbol "->", I mean, I understand the "$controller->function()" notation but when I see more "->" I just get lost, thank you again. |
Welcome Guest, Not a member yet? Register Sign In |