Multiple classes in one library - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Multiple classes in one library (/showthread.php?tid=15103) |
Multiple classes in one library - El Forum - 01-26-2009 [eluser]rvent[/eluser] Hello, I am creating a series of web applications and i was thinking to separate each app into its own library. But i wanted to know if it was possible to have more than 1 class defined in each library for example: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); and so on...? Thanks Multiple classes in one library - El Forum - 01-26-2009 [eluser]jalalski[/eluser] You can have as many classes defined as you like. But... You would normally load a library like this (in a controller for instance): Code: $this->load->library('testcenter'); In this scenario, the load function is looking for a file called testcenter.php and then looking inside for the class by the same name and instantiating it. However, you would also be able to do this: Code: $this->load->library('testcenter'); Take a look in the manual for the section called "Creating your own Libraries" for more details on naming and such. Multiple classes in one library - El Forum - 01-27-2009 [eluser]Phil Sturgeon[/eluser] The above way will work fine, but do you really need them in the same file? Might get a little confusing like that and as the classes grow it will be a nightmare to maintain. The following would work fine as two files: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Then you could load them like this: Code: $this->load->library('testcenter'); Multiple classes in one library - El Forum - 01-27-2009 [eluser]rvent[/eluser] [quote author="jalalski" date="1233032030"] Take a look in the manual for the section called "Creating your own Libraries" for more details on naming and such.[/quote] I did, but it didnt answer my question. You did.. Thanks to both of you, i ll take the recommendation and will keep each class in each file.. Thanks! Multiple classes in one library - El Forum - 01-27-2009 [eluser]Rey Philip Regis[/eluser] weird implemantation haha Multiple classes in one library - El Forum - 01-27-2009 [eluser]rvent[/eluser] [quote author="Rey Philip Regis" date="1233113189"]weird implemantation haha[/quote] You have never written a .dll with multiple related classes..? |