I've been checking out Ruby and Rails the past few days and I'm totally impressed. Does anyone know of any PHP project that is like Rails? What about a PHP version of the ActiveRecord? Does it seem possible to re-create Rails with PHP?
- matt
| SitePoint Sponsor |




I've been checking out Ruby and Rails the past few days and I'm totally impressed. Does anyone know of any PHP project that is like Rails? What about a PHP version of the ActiveRecord? Does it seem possible to re-create Rails with PHP?
- matt
I have been maintianing an "interested watch" status on rails. My biggest problem is that the code I write tends to interface with legacy data schemas on Oracle databases, neither of which is a sweet spot for rails![]()
Jason Sweat ZCE - jsweat_php@yahoo.com
Book: PHP Patterns
Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
Detestable (adjective): software that isn't testable.
Have you tried ObectGraph ... it says to support Oracle!Originally Posted by sweatje
I have not had a serious look at it yet, but it is on my todo list.Originally Posted by Dokkalfr
Jason Sweat ZCE - jsweat_php@yahoo.com
Book: PHP Patterns
Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
Detestable (adjective): software that isn't testable.
Just curious, what particular features do all of you like about Ruby of Rails?




I've been peeking at Ruby on Rails as well. I haven't gotten an example up and running, but I've read all the tutorials, some API docs, and a host of blog posts.
My assessment is that Rails is an MVC framework with distinct M, V, and C layers that uses introspection and a set of naming conventions to guess the proper wiring between components.
One of the drawbacks to MVC, for example, is that if you add a field to a table, then you have to update your program in at least three places: The M layer, the V layer and the C layer. The strength of Rails is that through introspection and naming conventions, it can automatically wire these three layers together, so you only have to make a change in one place.
The weakness of Rails, as Jason points out, is that if your three layers are not naturally parallel, then Rails won't know how to automatically wire them together and might even become a hinderance. The degree of freedom for the Model, View, and Controller layers to vary independently from each other in structure does not appear to be great under rails.
WACT and Rails are similar in many ways. WACT tries to provide support for all three layers of MVC, as does Rails. This allows for a greater degree of integration. I think it would be hard to do what Rails does without this integration between components.
I see many similarities between WACT and Rails at the controller level. In one of the earlier iterations of the WACT Controller, I had checked in a CRUD example that showed how to use parameterized controllers to perform CRUD operations. Unfortunately, I felt that people were confused by this and I removed it to make the example simpler. The example had only one table and the value of this approach is not clear unless you have many. However, I still use this approach in my own code.
For example, instead of creating a AddArticleController and a AddCategoryController, I would create an AddController with a parameter which might be 'Article' or 'Category.' It is possible to eliminate an amazing amount of code duplication in the controller layer with this technique. The WACT controller architecture is designed to support this capability.
Because of its controller layer, I think WACT can fairly easily do many of the things that Rails does. What does WACT lack right now for supporting a Rails apporach?
WACT does not have strong introspection support in the Model layer. The DB abstraction classes do not support examining table structures and the (young) ORM layer has little introspection capability at all. There is someone working on this, but they recently started a new job and their time is limited.
In the View layer, Jason has already written an introspection based component for displaying tabular data (The <data:table> tag). We need an equivalent for forms (<data:form>). Both of these tags will benefit from extra metadata that could be provided by an improved and explicit introspection capability.
One of the things I would like to see for WACT is the capability to define a Domain Object and then use the parameterized controller concept with introspection in order to form a CRUD application for that object.
So, for example:
I want it to be almost this simple for basic crud. So in this example the CrudController is responsible for creating sub controllers for each of the pages that one would see in a CrudApplication. Say:PHP Code:/*
* @orm.table article
* @orm.primary_key ArticleId integer auto_increment
*/
class Article extends DomainObject {
/*
* @orm.column title char(80)
* @orm.description Article Title
*/
var $Title;
/*
* @orm.column body text
* @orm.description Article Body
*/
var $Body;
}
$controller =& new CrudController('Article');
$controller->start();
CrudIndexController()
CrudDetailController()
CrudAddController()
CrudDeleteController()
CrudEditController()
Note that the basis for introspection in this example is the domain object, not a table schema as it would be in Rails. Also, you don't have to generate a bunch of skeleton files.
The hierarchical composability of WACT controllers would allow you to override portions that you want to change.
This is much the same approach that Rails takes. I've been working for a long time to allow even greater degrees of independence between the M, V, and C layers in WACT. I predict that this is exactly what Rails will try to do in future releases. For example, moving away from active record towards mapping.PHP Code:$controller =& new CrudController('Article');
$controller->addChild('index', new MyCustomIndexController());
$controller->start();
Anyway, I am very much keeping an eye on Rails.

I know I should't be talking about this before anything is released, but....
If you are interested in ActiveRecord: keep an eye out on my blog in 3-4 weeks, inspecting AR with PDO - full introspection and support for Postgres, Mysql and Sqlite so far ( no: nothing released yet, I'm keeping this until I get a chance to develop a proper application with it first )
A quick teaser
Everything is done with introspection ( no configuration at all, just a couple of rules that needs to be enforced - but these can be changed at runtime ) and a whole lot of __get/__set/__call functionality. Caching of the metadata is also done to ensure better performance. I will get back to this later on, just thought I would give a note about this if anybody needs this functionality and don't want to start on it.PHP Code:<?php
include( "settings.php" );
// Table: notes
class Notes extends ActiveRecord{ }
// Table: user
class User extends ActiveRecord
{
public function __construct()
{
parent::__construct();
// Each user has many Notes attatched to him/her
$this->hasMany( "notes:user" );
}
}
// Default we say that the primary key is 'id', but
// we can change this at run time before using the object
User::primaryKey( 'uid' );
$user = new User();
$me = $user->find( 1 );
echo "Hello, my name is: " . $me->username . "<br />";
echo "<ul>";
foreach( $me->notes as $comment )
{
echo "<li>" . $comment->id . "::" . $comment->title . "<br />";
echo $comment->note . "</li>";
}
echo "</ul>";
?>





Hello,
I'd be interested from the point of view of PDO![]()
Consider your blog bookmarked btw.




Yeah, what the Dr. said!
-m
OK, bloglined![]()
activeCollab
Project management and collaboration tool. On your server.





Porting ActionPack might be quite simple. The core is the routing. A set of routes are stored in an array:
Which is then compared with the query string from a .htaccess file's mod_rewrite:PHP Code:$routes = array(
"/archive/{date}/{action}/ | {controller => archive}",
"/{controller}/{action}/{id}/"
);
To give an associative array:PHP Code:$query_string = "/products/list/";
(Look at the Rails source for the logic behind this, should be easy to port.)PHP Code:$route = array(
"controller" => "products",
"action" => "list"
);
The next step is to call the controller. To isolate the controller from the view (which is just going to be a plain PHP template) we want to isolate the data output by the controller from the controller itself. Take this code:
Clever, isn't it? We can store the value saved in Alpha inside the variable which points to the Beta class! Translating this into our problem:PHP Code:class Alpha {
function store($data) {
$this->data = $data;
}
}
class Beta{
function Beta($data) {
Alpha::store($data);
}
}
$b = new Beta('Hello!');
echo $b->data;
Where the controller looks like this:PHP Code:class Runner {
function Runner($controller_name, $action) {
$this->template = $action; // more on this line later
eval("$controller_name::$action();");
}
}
Now we have a Runner class with $this->products set. Pass the Runner as a $data object to our template:PHP Code:class Products {
function list() {
$this->products = Products.find_all; // This could be a call to PDO
}
}
And a simple template calss (replace with SimpleT or similar to get caching and so on)PHP Code:// list.phtml
<table>
<?php foreach($data->products as $product) { ?>
<tr><td><?php echo $product->name ?></td></tr>
<?php } ?>
</table>
And all that is left is the code to call it all:PHP Code:class Template {
function render($data, $template_file) {
include($template_file);
}
}
Things in ActionPack like session handling can easily be added as there is support built into PHP. Other things like pre-filters need to be added, but theabove makes up the core of ActionPack, giving you the VC layers. The M layer could be PDO or Propel or another PHP ORM.PHP Code:$data = new Runner($route['controller'], $route['action']);
$t = new Template();
$template_file = $data->template . ".phtml";
$t->render($data, $template_file);
What do you all think?
Douglas
Hello World




I am working on the ActionPack implementation.
It is little more detailed than that, but you are right, it is not that difficult to port. Alot of the cool features in ActionPack use Ruby specific things, but most of it has an equivelant implementation in PHP.
The interesting thing is going to be trying to get the debugging and breakpoint functionality ported. I am looking into if Xdebug will work with this.
I like your simplified routing idea, i think i have been overcomplicating it actually![]()



Others are liking Ruby on Rails' ideas too.
Zealotry is contingent upon 100 posts and addiction 200?





Okay, not sure just how revalant this link is, but I came across it and seeing as we have had in the past, discussions on Hibernate and now Ruby on Rails, I thought I'd post it, Hibernate Vs Rails: The Persistence Showdown,
http://www.theserverside.com/article...RailsHibernate
Not had a read of it so please excuse me...
Try CAKE.
Cake is a framework for PHP, based on Rails.
The same, Solar ( http://www.solarphp.com )
How about we port Rails to PHP5
Call it "POW : PHP on Wings"![]()
Bookmarks