![]() |
is require_once required in CI? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: is require_once required in CI? (/showthread.php?tid=25640) Pages:
1
2
|
is require_once required in CI? - El Forum - 12-18-2009 [eluser]mason22[/eluser] I've made a controller that I want all my controllers to extend from. Unfortunately, all my other controllers don't have access to this controller class unless I call a require_once 'MY_Controller.php'. Is this the only way to go about including files for my files to use? is require_once required in CI? - El Forum - 12-18-2009 [eluser]Ben Edmunds[/eluser] No they do. Check your default extension in config.php. And make sure you put MY_Controller in the libraries folder. is require_once required in CI? - El Forum - 12-18-2009 [eluser]mason22[/eluser] [quote author="Ben Edmunds" date="1261198138"]No they do. Check your default extension in config.php. And make sure you put MY_Controller in the libraries folder.[/quote] "no they do" as in there is an easier way? I assumed there was a way for CI to automatically load it by looking at the prefix. My prefix is set to MY_ but it still comes up with errors. this is the error that I get.... Fatal error: Class 'MY_Common' not found in /opt/lampp/htdocs/test/system/application/controllers/contact.php on line 3 is require_once required in CI? - El Forum - 12-18-2009 [eluser]Colin Williams[/eluser] Maybe you should extend MY_Controller and not MY_Common... is require_once required in CI? - El Forum - 12-18-2009 [eluser]mason22[/eluser] [quote author="Colin Williams" date="1261202571"]Maybe you should extend MY_Controller and not MY_Common...[/quote] oops sorry. my controller was called "MY_Common". is require_once required in CI? - El Forum - 12-18-2009 [eluser]mason22[/eluser] My code still won't work >.< I've looked at the guides and I'm having no success. MY_Common.php looks like this: Code: class MY_Common extends Controller{ contact.php looks like: Code: class Contact extends MY_Common{ Fatal error: Class 'MY_Common' not found is require_once required in CI? - El Forum - 12-18-2009 [eluser]Armchair Samurai[/eluser] Change MY_Common.php to MY_Controller.php, but keep the content the same. is require_once required in CI? - El Forum - 12-18-2009 [eluser]Colin Williams[/eluser] Quote:Unfortunately, all my other controllers don’t have access to this controller class unless I call a require_once ‘MY_Controller.php’. You threw us all off with that. I thought you had a file MY_Controller.php with a class MY_Common declared in it. is require_once required in CI? - El Forum - 12-18-2009 [eluser]mason22[/eluser] [quote author="Armchair Samurai" date="1261218649"]Change MY_Common.php to MY_Controller.php, but keep the content the same.[/quote] Hey it worked!!!!!! thanks. is require_once required in CI? - El Forum - 12-19-2009 [eluser]bikuta[/eluser] So why did it have to be called MY_Controller.php? Is that because CI automatically loads Controller and MY_Controller (if it exists)? So the problem would've been because he didn't specify MY_Common to be loaded? |