Extending CI_Config class problem |
[eluser]gigowski[/eluser]
I am writing my own shopping cart application, actually rewriting it for CI. I was attempting to create a config subclass as shown here. I followed the instructions in the user guide, Creating Your Own Libraries. I keep getting the following error: Fatal error: Cannot redeclare class ci_config in /homepages/42/d187750613/htdocs/lilcharacters/system/libraries/Config.php on line 29 The name of my subclass is MY_Config and the filename is MY_Config.php and it's saved in the system\application\libraries folder. If I change the name of the file I get a message telling me it can't find the file. Does anyone know why this is happening? I call the MY_Config file up like so: Code: class Shop extends Controller { Here is the MY_Config.php code: Code: <?php Any help would be greatly appreciated.
[eluser]tonanbarbarian[/eluser]
Your problem is the following line in your controller Code: $this->load->library('config'); The user guide shows that the config class is loaded automatically (the fairly prominent Note at the top of the page) So trying to load the config library will result in the error you are getting because it is already loaded.
[eluser]gigowski[/eluser]
It isn't the core config class that I am trying to load. I want to load my config class which extends the core config class. How can I do that? When I comment out the line: Code: //$this->load->library('config'); I get this error: Fatal error: Call to undefined method: ci_config->db_config_fetch() in /homepages/42/d187750613/htdocs/lilcharacters/system/application/controllers/shop.php on line 8 I need it to load system/application/libraries/MY_Config.php but I can't figure out how.
[eluser]tonanbarbarian[/eluser]
Hmm it should be working I have successfully got it yo extend the Router class before and that is loaded automatically at the same time as the config (2 lines of code after) using exactly the same code
[eluser]Michael Wales[/eluser]
I'm thinking, since the native Config class is loaded by default - if you just create a file named MY_Config in /applications/libraries/ it would be loaded automatically. Just like, if I created MY_Validation in /application/libraries/ it would be loaded automatically when I called $this->load->library('validation')
[eluser]gigowski[/eluser]
[quote author="Michael Wales" date="1198151387"]I'm thinking, since the native Config class is loaded by default - if you just create a file named MY_Config in /applications/libraries/ it would be loaded automatically. Just like, if I created MY_Validation in /application/libraries/ it would be loaded automatically when I called $this->load->library('validation')[/quote] When I did that I received the following error: Fatal error: Call to undefined method: ci_config->db_config_fetch() in /homepages/42/d187750613/htdocs/lilcharacters/system/application/controllers/shop.php on line 8 I'm just going to change the MY_Config class so that it doesn't need to be extended form the core config class. I was just using the example I found in the wiki for making a database config. If anyone can think of why this wouldn't work, I'm still interested.
[eluser]Michael Wales[/eluser]
Quote:Fatal error: Call to undefined method: ci_config->db_config_fetch() in /homepages/42/d187750613/htdocs/lilcharacters/system/application/controllers/shop.php on line 8 Shouldn't it be: Code: $this->config->db_config_fetch()
[eluser]esra[/eluser]
Try removing the constructor from MY_Config, then load the controller to see if the method is available. |
Welcome Guest, Not a member yet? Register Sign In |