Re: separating C from V in MVC
by Dave Rolsky other posts by this author
May 31 2002 8:01PM messages near this date
Re: separating C from V in MVC
|
Re: [Mason] Re: separating C from V in MVC
On Fri, 31 May 2002, Barry Hoggard wrote:
> Do you have a favorite approach for writing the Model objects? At
> Investorama we created a class called TableObject that would deal with
> getting/setting values from the database, plus doing data verification
> like checking for values being present and well-formed XML in fields
> that needed it. I still use that approach on my consulting projects.
> It's not a very complex object, and it doesn't do things recursively,
> like mapping an attribute to an object and handling that object as well.
>
> TableObject doesn't act as a base class. It just becomes one of the
> attributes of the object.
>
> A typical invocation is something like this:
>
> my %fields = (
> id => { type => 'num', pkey => 1, sequence => 'seq_users' },
> email => { type => 'string', required => 1 },
> password => { type => 'string', required => 1 },
> first_name => { type => 'string', required => 1 },
> last_name => { type => 'string', required => 1 },
> valid => { type => 'num', required => 1},
> member_id => { type => 'num' },
> );
>
> my $table = NAIC::TableObject->new(DBH => $self->dbh,
> OBJECT => $self,
> TABLE => 'users',
> FIELDS => \%fields,
> VERIFY => 1);
>
> $table is then put into $self as an attribute called '_table'.
> Storing/retrieving/verifying are done with $self->_table->store etc. It
> expects that the attributes of an object like $self->email match the
> database columns.
Alzabo could handle a _lot_ of this for you. Class::DBI could handle some
of it (though less).
People should use one of those (and check out poop.sf.net for more
options) rather than re-inventing the wheel.
-dave
/*==================
www.urth.org
we await the New Sun
==================*/
Thread:
Jesse Erlbaum
Andy Wardley
Barry Hoggard
Sam Tregar
Andy Wardley
Sam Tregar
Perrin Harkins
Sam Tregar
Tony Bowden
Gunther Birznieks
Tony Bowden
Ed
Sam Tregar
Perrin Harkins
Jeff
Barry Hoggard
Rob Nagler
Dave Rolsky
Perrin Harkins
Jeff Aqua
|