DevShed has posted the next part of their series focusing on the CodeIgniter framework. This new tutorial looks at the Active Record class that sits at the heart of the framework.
Welcome to the sixth installment of the series entitled "Introducing the Code Igniter PHP Framework." By using a hands-on approach, this series of articles walks you through the main features that come packaged with this friendly yet powerful development software that lets you quickly build robust PHP applications.
They show a simple example of how to pull information out of your database, how to get a little more complex with conditional select statements and how to use a where to narrow down your results.
Bill Karwin (formerly of Zend and the Zend Framework project) has a new post to his blog defending one of the more abused (both in code and in opinions) design patterns, ActiveRecord:
ActiveRecord is fine. It is a tool that does just what it's designed to do. What sucks is when developers try to make it do other things than what it's intended to do.
He cites his work with the Zend_Db component and how Mike Seth gets it right when he says that the pattern shouldn't be "ActiveRecord-View-Controller". He compares the ideas of a true Model in an MVC application with the incorrect ideas that many developers seem to hold.
A Model is a class that provides a logical component of your application domain. Models are products of OO design, which is a development activity I see get very little attention in the developer blogosphere or the developer tools market.
Models can reference one or many (or no) database tables and are not where the hard work is being done. That's saved for the ORM (or ActiveRecord) to do.
Gergely Hodicska has posted part two of his look at the upcoming PHP 5.3 release. In his previous post, he looked at namespacing, but in this new one he covers late static binding (mor einfo here).
In the second part we will deal with static late binding, which is a very exciting new feature in PHP 5.3 and which promise some really nifty code. :) This topic attracted attention after Zend Framework. There was a little outcry in the PHP blogosphere, that the ActiveRecord examples presented in this webcast can't work in PHP even with the version 5.2. Now with late static binding it is possible to implement this style of ActiveRecord almost correctly.
His post is an example of implementing the ActiveRecord (sort of) pattern, complete with code examples.
In a response to a response (from Arnold Daniels) on his article on the ActiveRecord pattern in PHP, Flinn Mueller has come back once again with more comments, both in response and to share some more opinion on the matter.
Today I saw a big traffic increase from my PHP and ActiveRecord post. It looks like PHPDeveloper posted a link to the article and response, so I've written a response to the Arnold's wor(l)ds response post. Arnold's post is insightful, references runkit and has a good implementation of a Sortable tasklist example in PHP.
Flinn breaks it out into a few different topics - things like:
Ruby objects are (native) Ruby objects
a brief look at "lineage" for both PHP and Ruby
The usefulness of Ruby mix-ins
Issues with static inheritance in PHP
and some of his suggestions on what PHP6 really needs
In response to this post on the ActsAsFlinn blog's comments on ActiveRecord in PHP, Arnold Daniels has some comments of his own on the subject - specifically about the need for more work on the object oriented side of things in PHP natively.
Today I read an article about how Active Record is implemented in Ruby. In this article he lays down how things are done in Ruby and how that is not possible on PHP. Though I agree with him on a large part, there are a few site notes to make here.
Arnold talks about a solution to an issue mentioned in the ActsAsFlinn blog - the addition of methods to a preexisting class - via the runkit extension. He gives a PHP translation of the Ruby code from the other post and includes a few proof of concepts to show it in action. You can download the code if you'd like to try it out yourself.
On the ActsAsFlinn blog, a new article's been posted talking about ActiveRecord and some of the problems with implementing it in PHP.
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.
His experience found that there were a few things that caused the problem in the transition between Ruby and PHP like "in Ruby everything is an object" and some Reflection differences between the two languages. He has a little sample object he's created the code for, but it still doesn't work quite right.
In the end, he points out that the Row Data Gateway is a much easier method to get working in PHP (complete with sample code).
On his blog today, Hasin Hayder has a quick tutorial on using one of the features of the CodeIgniter framework outside of it - the ActiveRecord library.
CodeIgniters ActiveRecord library is a nice implementation (though modified) of ActiveRecord design pattern. It comes bundled with CodeIgniter. So if you want to use Just this library in your application individually instead of using full CodeIgniter framework, what to do?
His solution uses an abstraction layer (ActiveRecordFactory) to handle any issues with interfacing to CodeIgniter's class. He's also included the code (and a download
In his latest blog post, Chris Shiflett talks about CakePHP "visiting" New York at this month's NYPHP meeting as well of some of his impressions on the framework.
Last night at the monthly NYPHP meeting, Nate Abele presented an introduction to CakePHP, a web application framework. The New York subway wasn't cooperating with my schedule, and due to a problem affecting all uptown 4/5 trains, I was 30 minutes late to the talk.
Here are some of my notes from the talk as well as the conversation we had over dinner and drinks later.
He wonders about if the fact that Cake supports PHP4 hinders it, the scaffolding available, Ajax functionality, and, of course, some of the security features of the framework. He notes that "as long as you stick to the Cake way of generating output, it handles the escaping for you" - definitely a plus.
After two weeks I finally managed to find a bit of time to continue working on CWAC_ActiveRecord. Requested by my friend Arnaud was the setConnection() method, that allows to reuse existing PDO objects with CWAC_ActiveRecord. Before this, you could only pass a DSN with the config array and a new connection would always be created.
He also added limit() and orderby() methods to help narrow down your queries.
John Lim has posted an example of using the ADOdb software he's a developer on to clone the functionality of Zend's Zend_Db_DataObject.
The Zend Framework Preview edition is out. I had look this morning at Zend_Db_DataObject, which is an implementation of the Active Record pattern. After reading the tutorial, decided to implement something similar for ADOdb. After a couple of hours coding, I had an implementation that works with both PHP4 and PHP5, and provides a superset of the functionality described in the above link.
ActiveRecord, a method of database usage where the tables can "self-define" in your script (and you work with objects instead of messing with columns) is cropping up more and more, and Johngives a code example of how it can be used inside ADOdb as well. He also mentions some of the advantages to using this kind of code/library, including the fact that it will work with both PHP4 and PHP5.