Welcome Guest, Not a member yet? Register   Sign In
OO usage in code igniter structure, Model, Controller
#2

[eluser]m4rw3r[/eluser]
The best way to get OO interaction with the database in CI (without writing it yourself) is to use one of the ORM tools available.
Mine is one among them (IgnitedRecord, link in my signature).

That about creating a instance of an object, just do it as you do in normal PHP, CodeIgniter is "just" a framework (but an awesome one Smile).
Model example:
Code:
// in a model

// almost right after <?php if(defined(...
require_once 'record_file.php';
// you can store the "record" class in the model file,
// but I personally prefer to have it in a separate file

// in a method in the model class
// this one fetches a single db row and passes the data to the Record class
$q = $this->db->get_where('some_table', array('somecol' => 'somedata'), 1);

if($q->num_rows())
    return new Record($q->row_array());
else
    return false;
But I recommend to split up the responsibilities into different parts; models handle data fetching/saving, views the displaying of the result to the user, controllers are the "glue" and uses models, libraries and views to produce a result and libraries/helpers does the rest.
I'm telling you this because it is easy to forget when you start to mix MVC with ordinary OO programming Wink


Messages In This Thread
OO usage in code igniter structure, Model, Controller - by El Forum - 11-14-2008, 04:07 PM
OO usage in code igniter structure, Model, Controller - by El Forum - 11-15-2008, 02:14 PM
OO usage in code igniter structure, Model, Controller - by El Forum - 11-15-2008, 04:33 PM
OO usage in code igniter structure, Model, Controller - by El Forum - 11-15-2008, 04:41 PM
OO usage in code igniter structure, Model, Controller - by El Forum - 11-15-2008, 05:28 PM
OO usage in code igniter structure, Model, Controller - by El Forum - 11-15-2008, 06:14 PM
OO usage in code igniter structure, Model, Controller - by El Forum - 11-15-2008, 07:25 PM



Theme © iAndrew 2016 - Forum software by © MyBB