Link Details

Link 34277 thumbnail
User 225135 avatar

By skoop
via actsasflinn.com
Published: Aug 10 2007 / 09:08

I’m starting a new job soon and I’ll be working primarily with PHP. Since I’ve been a rubyist for the last 2 years I’m looking at PHP from a Rails development perspective. Before working exclusively with Ruby I hung onto to PHP (because of the project I was working on) by porting Rails bits to PHP. I eventually gave up on porting Rails to PHP after my project’s funding was cut.
  • 15
  • 1
  • 2657
  • 0

Comments

Add your comment
User 205523 avatar

fredbh replied ago:

0 votes Vote down Vote up Reply

There is another one, MyActiveRecord to php+mysql
http://www.phpclasses.org/browse/package/2990.html
its cool

User 228310 avatar

bmharris replied ago:

0 votes Vote down Vote up Reply

The whole static methods and inheritance in PHP is a bit of a bother, but its the language. To bypass the problem described in the article where Person extends Base, and Base has a find(id) method, in order to do Person::find(id), Person just needs to implement find, and call parent::find(__CLASS__, id), and change Base::find to accept the class, and be protected. Not as elegant as Ruby, or Java, but not horrible.

User 202743 avatar

joshdavey replied ago:

0 votes Vote down Vote up Reply

Check out Madeam's activeRecord pattern. It doesn't use static methods but does take advantage of magic methods, reflection and method chaining.

Typical Model in Madeam:
class articleModel extends madeamActiveRecord {
var $has_many_comments;
var $has_one_user;

var $validate_title_is_notempty = array('message' => 'Please fill in the title');
}

Use of the model in a controller. (Note there is no "loading" of models! They are loaded dynamically into the controller when you use them.

// return all articles
$this->Article->order('id DESC')->fields('title', 'id', 'body')->limit(25)->find_all();

// limit the number of articles returned after finding an article
$this->Article->Comment->limit(10);
$this->Article->find_one(32);

How sweet is that? check it out: www.madeam.com

Screencasts: www.madeam.com/screencasts/

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Apache Hadoop
Written by: Piotr Krewski
Featured Refcardz: Top Refcardz:
  1. Play
  2. Akka
  3. Design Patterns
  4. OO JS
  5. Cont. Delivery
  1. Play
  2. Java Performance
  3. Akka
  4. REST
  5. Java