Liquid Fire Posted September 16, 2008 Share Posted September 16, 2008 I have a question and want to get some opinions on which method to go with. This is what i am trying to decide for the ORM portion of my framework. The Problem: Lets say i have a project management system. Lets just take a projects table and issues table for this problem. Now the issues table would have a field called project_id which would be a foreign key to the project table primary key. Now logical we would want a function in the project model called get_issues which would return all issues with the project id the matches the project calling the function. Now what i want is the ability to call a function while just passing the project id(at a minimum). Option 1: The first option is to have a separate class that will store just static functions so that i would be able to just do(i am jut using peer as that is was propel does, since not sure what i name the static function holding class): <?php //project_model's get_issues function public function get_issues() { return issue_peer::get_by_project($this->id); } ?> PROS: Can run on PHP 5.X CONS: requires more files to be loaded(2 files per model as the base peer file and the custom peer file which the user can edit) Option 2: The second option requires php 5.3, and more specifically the late static binding functionality. Basically instead of have the separate class for all the searching static functions, the user can just add the static function to the custom model file. so the code would look like: <?php //project_model's get_issues function public function get_issues() { return issue_model::get_by_project($this->id); } ?> PROS: Less files to load Code flows a little more natural(at least to me) CONS: Requires PHP 5.3 My personal choice is option 2 because the code seems to be a bit cleaner and more intuitive to me. The only thing that is not making me just go with option 2 is that i now can not setup php 5.3 with PDO support on my window test machine which mean i have to use wamp with php 6 and i can not do any good speed test since xdebug does not support php 6(and why would it). What do you guys think? Also if you like option 1, is it mainly because it does not require php 5.3? 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.