Welcome Guest, Not a member yet? Register   Sign In
Using an own Class (= Library)
#1

[eluser]dsentker[/eluser]
Hey there,

i've got an own Database class (e.g. to return last 5 DB Entrys etc.). In a non-CI-Framework Project i would use my class like that:

Code:
$mydb = new MyDBClass;
$mydb->connect();
$mydb->returnlastentrys(5);
//etc.

This Class is stored in mydb.class.php.

I've read in the user documentation, that i can implement my own class with the Library feature:

Code:
$this->load->library('mydb.class');

and now i can act with my methods like that:

Code:
$this->mydb.class->connect();
//etc.

Is that right?

Next Q: The Connect Method, for example, is a method where is no need to load it multiple. If the method was started once, its not essential to start it twice.

Where do i have to place the
Code:
$this->mydb.class->connect();
//etc.
? Do i have to place it in the constructor of the Controller? That could be annoying, if i have many Controllers, and every Controller needs a Connection to the DB. Can i check if a method was called before? Like that:

Code:
$this->mydb.class->connect(); //returns true, connection is built now
// any other code and another Controller...
// [...]
if($this->mydb.class->connect() == TRUE) {
   echo 'Connection is already there!';
} else {
   echo 'Not connected - trying to connect...';
   $this->mydb.class->connect();
}


Messages In This Thread
Using an own Class (= Library) - by El Forum - 01-03-2010, 02:09 PM
Using an own Class (= Library) - by El Forum - 01-03-2010, 02:10 PM
Using an own Class (= Library) - by El Forum - 01-03-2010, 02:15 PM
Using an own Class (= Library) - by El Forum - 01-04-2010, 07:17 AM



Theme © iAndrew 2016 - Forum software by © MyBB