Welcome Guest, Not a member yet? Register   Sign In
Question about Models and Libraries
#1

[eluser]gedev2006[/eluser]
Hi

The model and library loader is quite annoying really. Lets say i have a model, called "customers". It may look like this:

Code:
Class Customers extends Model {

    public function getCustomers() {

        $_result = $this->db->query ( "SELECT * FROM `customers`" );

        if ( $_result->num_rows() ) {

            $_customers = array();

            foreach ( $_customers->result() as $customer ) {

                 $_customers[] = new Customer ( $customer );

            }
            return $_customers;
        }

     }

}

as you can see what i want to do is return an array of "customer" objects. Where the customer class is a custom class maybe like this:

Code:
class Customer {

    private $_customerObj = NULL;

    public function __construct ( $customerObj ) {

        $this->_customerObj = $customerObj;
    }


    public function getName() {

        return $this->_customerObj->name;

    }

}

now the only way i can see to do this is to have the Customer class underneith or above the model in the same file. I did think about creating it as a library, but thince $this->load->library ( 'customer', array ( $customer ) ); would not return the object of the Library, i cannot create the $_customer array.

Any ideas?
#2

[eluser]Jeffrey Lasut[/eluser]
If I were you I would take a look at DMZ/datamapper:
http://ellislab.com/forums/viewthread/112904/




Theme © iAndrew 2016 - Forum software by © MyBB