Welcome Guest, Not a member yet? Register   Sign In
MVC structural advice - separation of code
#8

[eluser]Lyon[/eluser]
Sorry, I had to abandon the project for a while while I got another project sorted.
I could have sworn I replied to this :-S my bad :red:

I think what you were meaning was something like :
Code:
$user = new User();
$user->username = "my_username";
$user->password = "my_password";
$user->Save();

I'm not really sure how that would work though.
Would it be something like :
Code:
class User
{
    private $db = null;
    private $CI = null;

    public $username = '';
    public $password = '';
    public $id = -1;

    public function __construct()
    {
        $this->CI &= get_instance();
        $this->db = $this->CI->load->database('user', true);
    }

    public function save()
    {
        $this->db->insert('users', array("username" => $username, "password" => $password));
        $this->id = $this->CI->insert_id();
    }

    public function get_from_username($username)
    {
        $this->db->from('users');
        $this->db->where("username", $username);
        $query = $this->db->get();

        if($query->num_rows() !== 1) return false;

        $row = $query->row();
        $this->username = $row->username;
        $this->password = $row->password;
        $this->id = $row->id;
    }
}

Or would it be different, there seem to be a lot of CRUD tutorials on the internet, but apart from using Doctrine I cannot find any using objects, just arrays of information passed to a model.

Or should I just use Doctrine for CRUD?

Thanks.


Messages In This Thread
MVC structural advice - separation of code - by El Forum - 06-15-2010, 02:31 PM
MVC structural advice - separation of code - by El Forum - 06-15-2010, 06:07 PM
MVC structural advice - separation of code - by El Forum - 06-16-2010, 07:32 AM
MVC structural advice - separation of code - by El Forum - 06-16-2010, 07:37 AM
MVC structural advice - separation of code - by El Forum - 06-16-2010, 09:11 AM
MVC structural advice - separation of code - by El Forum - 06-16-2010, 03:00 PM
MVC structural advice - separation of code - by El Forum - 06-16-2010, 03:07 PM
MVC structural advice - separation of code - by El Forum - 07-22-2010, 06:09 AM
MVC structural advice - separation of code - by El Forum - 07-22-2010, 06:24 AM
MVC structural advice - separation of code - by El Forum - 07-22-2010, 09:29 AM
MVC structural advice - separation of code - by El Forum - 07-22-2010, 11:05 AM
MVC structural advice - separation of code - by El Forum - 07-22-2010, 11:09 AM
MVC structural advice - separation of code - by El Forum - 07-22-2010, 11:16 AM
MVC structural advice - separation of code - by El Forum - 07-22-2010, 11:25 AM
MVC structural advice - separation of code - by El Forum - 07-22-2010, 11:51 AM
MVC structural advice - separation of code - by El Forum - 07-22-2010, 12:25 PM
MVC structural advice - separation of code - by El Forum - 07-22-2010, 12:55 PM
MVC structural advice - separation of code - by El Forum - 07-22-2010, 01:03 PM
MVC structural advice - separation of code - by El Forum - 07-22-2010, 01:29 PM
MVC structural advice - separation of code - by El Forum - 07-22-2010, 01:50 PM
MVC structural advice - separation of code - by El Forum - 07-22-2010, 02:29 PM
MVC structural advice - separation of code - by El Forum - 07-01-2012, 09:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB