Welcome Guest, Not a member yet? Register   Sign In
Multiple classes in one library
#1

[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');

class Testcenter
{
   function one
   {
   }
}

class Test extends Testcenter
{
   funtion addTest()
   {
   }
}
?>

and so on...?

Thanks
#2

[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');
$this->testcenter->dosomething();

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');
$t = new Test();
$t->addTest();

Take a look in the manual for the section called "Creating your own Libraries" for more details on naming and such.
#3

[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');

class Testcenter
{
   function one
   {
   }
}

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Test extends Testcenter
{
   funtion addTest()
   {
   }
}
?>

Then you could load them like this:

Code:
$this->load->library('testcenter');
$this->load->library('test');
#4

[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.. Wink

Thanks to both of you, i ll take the recommendation and will keep each class in each file..

Thanks!
#5

[eluser]Rey Philip Regis[/eluser]
weird implemantation haha
#6

[eluser]rvent[/eluser]
[quote author="Rey Philip Regis" date="1233113189"]weird implemantation haha[/quote]

You have never written a .dll with multiple related classes..?




Theme © iAndrew 2016 - Forum software by © MyBB