[TYPO3-ect] MVC Project
Jeff Segars
jsegars at alumni.rice.edu
Wed Feb 1 18:49:59 CET 2006
Hey Elmar (and anyone else who wants to chime in),
I've been away from the newsgroup a while (way too busy with work,
followed by a nice relaxing vacation) and I returned to find a flurry of
activity around here. Exciting things being discussed!
One thing I've seen mentioned in passing in several different threads is
an MVC project. Several of us within Web-Empowered Church have been
working on a TCA-based Object-Relational Mapper which could potentially
form the basis for the model portion of an MVC project.
The general idea with our mapper (called tcaObj) is that the TCA already
contains the info we need to read and write data from the database
(table name, field names, field types, validation requirements, etc).
The backend proves this with the use of TCEMain and TCEForms.
What we're doing is very similar to what the backend does, but is
wrapped in objects instead. Each tables within the TCA is available as
an object, and each column within a TCA entry is a dynamically created
object with getters and setters. find(), findAll() and save() methods
are available to transfer the data between the database and the object
model.
I've put a couple code examples below to try to demonstrate the
direction we're heading. Does this match up with anything you've been
thinking about for possible use in the MVC project?
Thanks,
Jeff
Example Code - Basic
*******************************
The basic example code utilizes the standard tcaObj and requires no
configuration other than that available in the TCA. Simply call a find
or findAll method of tcaObj and the model is automatically populared.
Objects are available for every TCA column and complex column types such
as group and select have arrays of child objects associated with them.
*******************************
$user = tx_tcaobj::find(3); // Returns the user object with ID 3
$user->username->getValue() => "jeff"
$user->email->getValue() => "jeff at email.com"
$user->username->setValue() => "jsegars"
$user->save(); // Saves user object back to database
$groups = $user->group->getObj(); // Returns an array of group objects
$groups[0]->name->getValue() => "ECT Team"
Example Code - Custom Class
*******************************
The custom class example behaves in much the same way as the standard
tcaObj. Rather than calling this standard class, though, a custom class
for users is invoked. This class extends tcaObj by adding special
methods that are specific to tx_user. All of the functionality of the
standard tcaObj is still available, but the model has been decorated
with additional functionality specific to it.
*******************************
$user = tx_user::find(3); // Returns the user object with ID 3
$user->username->getValue() => "jsegars"
$user->usernameToUpper() => "JSEGARS"
More information about the TYPO3-team-extension-coordination
mailing list