Welcome Guest, Not a member yet? Register   Sign In

Hey there!

I've been using CodeIgniter for a little bit now, but I'm still learning quite a bit. However, I've recently run into something of a hiccup... OOP. How would one go about doing object-oriented programming with CodeIgniter?

I understand that CodeIgniter is OOP in and of itself. However, what if I want to make, say, a member class. Where would I put it? How would I load new members? With libraries, for example, I know that I can load a library, but how would I write something along the lines of "$person = new Member($member_id);" ?


Extending 'CI_Model' these represent objects that act a a 'middleman' for interacting with the db. Take a quick look at MVC design patterns to get an overview of it.

You would create a "members" class and put it in the /application/libraries directory.

Instead of: $person = new Member($member_id);”
You would:
$this->load->library('members', $member_id);  //$member_id gets passed to the __construct method of the members class.

$person = $this->load->library('members', $member_id, 'person');
Please see the User Guide for Creating Libraries for more info. You should also read up on the loader class, if you want your new object returned as a variable instead of extending the CI superobject. The rest of the user guide has some interesting things to read as well. Strange, I know.

That second example looks like it's what I want. I was unaware you could load something directly into a variable that way. Thanks!

Theme © iAndrew 2016 - Forum software by © MyBB