Welcome Guest, Not a member yet? Register   Sign In
Extend Active Record Class
#4

[eluser]m4rw3r[/eluser]
This:
Code:
class Type{
    function Type($data = array()){
        foreach($data as $key => $val){
            $this->$key = $val;
        }
    }
}
$query = $this->db->get_where('types',array('id' => $typeId));
$row = $query->row_array();
$type = new Type($row);
is actually marginally faster than this:
Code:
class Type{

}
$query = $this->db->get_where('types',array('id' => $typeId));
$type = mysql_fetch_object($query->result_id,'Type'));
The lower one requires MySQL and PHP 5 or higher, so I think you should use the first one.

About the includes: There is no "CI way" of including associated classes, not yet at least.
But do what you feel is right, include, require (or the *_once), $this->load->library(...) or whatever.
I recommend using the APPPATH constant (yes three PConfused, it is the path to your application folder) in your includes/requires, like this:
Code:
require_once APPPATH.'/myclassdir/type.php';


Messages In This Thread
Extend Active Record Class - by El Forum - 06-08-2008, 03:39 AM
Extend Active Record Class - by El Forum - 06-08-2008, 07:14 AM
Extend Active Record Class - by El Forum - 06-09-2008, 12:30 PM
Extend Active Record Class - by El Forum - 06-09-2008, 02:23 PM



Theme © iAndrew 2016 - Forum software by © MyBB