redbullmarky Posted May 18, 2008 Share Posted May 18, 2008 Hi all Just wanted to get some thoughts from those experienced with ORM. I've been looking at both Django and Rails a bit more recently with a view to getting ideas for a newspaper CMS I've been building, especially with regards to Django's automatically generated admin interface. I know I could use Python and Django for what I'm doing, but there are many reasons why I want to stick with PHP... The idea: I have a "manager" class which handles retrieval of records from a database table. I'd expect to have a 'find' method and a 'load' method. The find method would be concerned with finding multiple records where as a load would be concerned with returning a single record. The loader would return an object that could be accessed with 'save()', etc methods, the finder would return an object which would enable iteration through these sorts of objects. Hope that makes sense, but examples of all: <?php $u = UserManager(); $records = $u->findAll("created_at > $sometimestamp"); while ($record = $records->next()) { echo $record->username . '<br />'; } $user = $u->load(1); // load record 1 echo $user->username; $user->username = 'test_person'; $user->save(); $user = $u->create(); $user->username = 'another'; $user->password = 'password'; $id = $user->save(); // etc // etc ?> my questions: 1, is there a better, cleaner way of implementing Row Data Gateway / Table Data Gateway in PHP, considering the handy features PHP lacks that Ruby/Python have? 2, does anyone have a clue what performance is like? Consider, for example, I want a list of 20 articles on a 'list' or 'archive' page, i'd need to run the 'manager' to get 20 results, each of which would in turn be represented by a new object? Cheers Mark Quote Link to comment Share on other sites More sharing options...
trq Posted May 19, 2008 Share Posted May 19, 2008 Have you taken a look at any of the many php orm's already around? I hear Doctrine is pretty sweet. Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted May 19, 2008 Author Share Posted May 19, 2008 yeah i've taken a look at a few, but generally they look quite "excessive" whereas i suppose (although my description above probably doens't show it ha!) I need something very very basic that I can plug in easily and just keep adding functionality to along the way as I need it. I suppose also that it's a little exercise for me too to get something nice like this working myself, as the rest of my framework is custom code. so i guess I'm just trying to find out how "expensive" it is to have each record represented by a CRUD-type object, each table represented by a "manager" object which can find rows and return these CRUD objects. thanks for the suggestion though - if nothing else it'll perhaps give me a few ideas. I just love the way Django does it though - very powerful but incredibly simple. Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted May 19, 2008 Author Share Posted May 19, 2008 one possible way i've stumbled upon to get a collection of objects is possibly via the use of PHP5's object iterator: http://uk3.php.net/manual/en/language.oop5.iterations.php Which would allow me to effectively run a foreach on a resultset object to return CRUD objects one by one as required, without instantiating one for each result in advance. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.