SitePoint Sponsor |
|
User Tag List
Results 1 to 17 of 17
Thread: Ruby on Rails -> PHP?
-
Mar 24, 2005, 08:38 #1
- Join Date
- May 2003
- Location
- virginia
- Posts
- 988
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ruby on Rails -> PHP?
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
-
Mar 24, 2005, 08:46 #2
- Join Date
- Jun 2003
- Location
- Iowa, USA
- Posts
- 3,749
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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.
-
Mar 24, 2005, 11:22 #3
- Join Date
- Mar 2005
- Posts
- 53
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Just curious, what particular features do all of you like about Ruby of Rails?
-
Mar 24, 2005, 14:36 #4
- Join Date
- Nov 2002
- Posts
- 841
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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:
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.
PHP Code:$controller =& new CrudController('Article');
$controller->addChild('index', new MyCustomIndexController());
$controller->start();
Anyway, I am very much keeping an eye on Rails.
-
Mar 24, 2005, 16:01 #5
- Join Date
- Aug 2002
- Posts
- 178
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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
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>";
?>
-
Mar 24, 2005, 16:24 #6
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hello,
I'd be interested from the point of view of PDO
Consider your blog bookmarked btw.
-
Mar 24, 2005, 16:34 #7
- Join Date
- May 2003
- Location
- virginia
- Posts
- 988
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yeah, what the Dr. said!
-m
-
Apr 7, 2005, 00:09 #8
- Join Date
- Oct 2003
- Location
- Serbia
- Posts
- 27
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
OK, bloglined
activeCollab
Project management and collaboration tool. On your server.
-
Apr 7, 2005, 16:54 #9
- Join Date
- Nov 2001
- Location
- Bath, UK
- Posts
- 2,498
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Porting ActionPack might be quite simple. The core is the routing. A set of routes are stored in an array:
PHP Code:$routes = array(
"/archive/{date}/{action}/ | {controller => archive}",
"/{controller}/{action}/{id}/"
);
PHP Code:$query_string = "/products/list/";
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:
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;
PHP Code:class Runner {
function Runner($controller_name, $action) {
$this->template = $action; // more on this line later
eval("$controller_name::$action();");
}
}
PHP Code:class Products {
function list() {
$this->products = Products.find_all; // This could be a call to PDO
}
}
PHP Code:// list.phtml
<table>
<?php foreach($data->products as $product) { ?>
<tr><td><?php echo $product->name ?></td></tr>
<?php } ?>
</table>
PHP Code:class Template {
function render($data, $template_file) {
include($template_file);
}
}
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?
DouglasHello World
-
Apr 7, 2005, 22:29 #10
- Join Date
- Jul 2002
- Location
- Melbourne, Australia
- Posts
- 678
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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
-
Apr 15, 2005, 14:27 #11
- Join Date
- Jun 2003
- Location
- Melbourne, Australia
- Posts
- 440
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Others are liking Ruby on Rails' ideas too.
Zealotry is contingent upon 100 posts and addiction 200?
-
Apr 15, 2005, 14:44 #12
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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...
-
Apr 29, 2005, 07:56 #13
- Join Date
- Apr 2005
- Location
- Atlanta, GA
- Posts
- 2
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Try CAKE.
Cake is a framework for PHP, based on Rails.
-
Apr 30, 2005, 08:59 #14
- Join Date
- Sep 2004
- Location
- Hanoi
- Posts
- 22
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The same, Solar ( http://www.solarphp.com )
-
May 1, 2005, 14:35 #15
- Join Date
- Jun 2004
- Location
- Montreal
- Posts
- 88
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How about we port Rails to PHP5
Call it "POW : PHP on Wings"
-
Dec 22, 2005, 20:43 #16
- Join Date
- Jan 2004
- Location
- Continente de São Pedro
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by sweatje
-
Dec 22, 2005, 22:09 #17
- Join Date
- Jun 2003
- Location
- Iowa, USA
- Posts
- 3,749
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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.
Bookmarks