I have a useful object written in PHP lets call it my_class.php
<?php
class my_class{
var property;
function __construct($conn){
$query = "SELECT * FROM bla bla bla";
$rs2 = mysql_query($query , $conn);
//... do stuff with results etc.
}
function do_something(){
//more code here
}
}
?>
What I would like to do with this class is to be able to use it inside of the admin section of the EE site, in the following way:
$this_obj = new my_class($conn);
The concerns that arise from this are the following:
1) $conn would be a connection to MySql when you're sort of outside EE, and it would be better to place this somewhere where it is possible to use the EE database calls.
2) where would you put a class, so that EE can instiantate it many times?
To make this object useful, it will need to be instantiated dozens of times, and I'll want to be using an array of these objects rather than just one instance.
Thanks in advance for any insight!
You may want to take a look through the CodeIgniter docs. ExpressionEngine is based on CI, so if you're looking for best practices look at the CI docs.
You can store your class files wherever you want - but most people store the in libraries/ or lib/ within the addon folder they are developing. That way you can call $this->EE->load->library('whatever');
Take a look at models for making database calls - also take a look at the CI DB / ActiveRecord Class and the DB forge class.
Hope that helps!