2009年1月30日星期五

Re: [fw-mvc] Re: Separating Models from DB Access

Looks pretty logical, only one comment is that do you want to lock
yourself to one table per gateway? Other than that it looks pretty
good, I would do a prototype of it and see how the implementation
goes, I went through a few designs as some of my early prototypes
became a bit unwieldy. Just remember to set some clear goals for what
you want to achieve, in my case I wanted to be able to test without
the need for a database connection, therefore I abstracted more than
usual.

2009/1/30 Jack Sleight <jack.sleight@gmail.com>:
> Hi Everyone,
> Thanks for your help, I've been reading up on various methods of doing
> this, and found this article very useful
> http://weierophinney.net/matthew/archives/202-Model-Infrastructure.html.
> I've now got the beginnings of something that could work, this is my
> basic set up so far, feedback would be very welcome:
>
> (This is working with Site entities not Users)
>
> class Site
> {
> protected $_row;
> protected $_data;
>
> public function __construct(Zend_Db_Table_Row $row, array $data = null);
> public function save();
> public function setBatch($data);
> public function __set($name, $value);
> public function __get($name);
> public function __isset($name);
> public function __unset($name);
> }
>
> class Site_Gateway
> {
> protected $_table;
>
> public function __construct();
> public function create($data);
> public function fetch($id);
> public function fetchPrimary();
> public function fetchAll();
> }
>
> class Site_Set implements Iterator, Countable
> {
> protected $_items = array();
> protected $_index = 0;
>
> public function __construct(array $items);
> public function count();
> public function current();
> public function key();
> public function next();
> public function rewind();
> public function valid();
> }
>
> So, basic logic: You use Site_Gateway to retrieve Site objects or
> create new site objects. fetch*() methods return either a Site object
> or a Site_Set object that contains multiple site objects.
>
> When a Site object is created the data is copied out of $row and into
> $data, sets/gets are performed on $data and upon save() the date is
> copied into the row, saved and then copied back out (in case anything
> changed, eg. AUTO_INCREMENT fields).
>
> Site::__construct() takes an additional array of data.
> Site_Gateway::create() gives the Site object it creates an empty $row
> and the array of data.
>
> When values are set on Site they are filtered and validated. If
> validation fails an exception is thrown. When Site::setBatch() is used
> thrown exceptions are caught and the errors aggregated, they are then
> all thrown in one Exception object, this is so you can report multiple
> validation errors back to the UI, rather than one field at a time.
>
> Any comments, suggestions etc.?
> Cheers,
> Jack
>
>

--
----------------------------------------------------------------------
[MuTe]
----------------------------------------------------------------------

没有评论: