0

I want to use objects(java style) in my PHP code after by instantiating objects after getting their properties from database and use them as objects from that point on. Does this work in PHP? If yes,where should I place my classes in the codeigniter directories?

$object=object_constructor($this->model_name->function_that_fetches_object_properties());
1
  • 1
    you could use PDO to fetch a row into an object. Commented Apr 18, 2011 at 20:29

2 Answers 2

1

What you are looking for is what is called an ORM which codeigniter does not have "out of the box".

There are some that integrate it with Doctrine, I would recommend you look at other php frameworks that have a built in ORM, one that is somewhat similar to codeigniter in approach is FuelPHP. It is approaching a stable release and has been enjoyable for me to work with.

ORM example in FuelPHP:

$entry = Model_Article::find(4);
$entry->title = 'My first edit';
$entry->author = 'Total n00b';
$entry->save();
Sign up to request clarification or add additional context in comments.

Comments

0

I suggest you use PEAR's DB_DataObject which does exactly this kind of mapping, including fetching related objects.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.