Page 3 of 3

Re: Resultset total count - simple question

Posted: Thu Sep 23, 2010 5:09 pm
by VladSun
I don't feel like I will use the "passive V MVC".

Thanks to this thread I've cleared myself about using decorations of the Model inside the View scope. I had a thread about arguing that the pagination (filtering, ordering, etc.) logic must not be implemented by the Model, but by the View because it's a pure View requirement. I've put my Pagination (etc.) plugin into the Controller (into it's constructor model initialization), but while reading this thread I've realized it should be in the View. So, now I have:

Controller

Code: Select all

class User extends CollectionController
{
    ...
    public function getUsers
    {
        $this->model = new UserCollectionModel();
        $this->view('getUsers', $model);
    }
} 
View

Code: Select all

$model = new GridCollection($this->model);
$users = $model->getAll();
...
(... DO SOMETHING WITH $users ...)
My GridCollection decorator is just a ... hm ... facade:

Code: Select all

class GridCollection extends DecoratorCollection_Model
{
	public function  __construct($model, $conf = null)
	{
		parent::__construct(new FilteredCollection(new OrderedCollection(new LimitedCollection($model, $conf), $conf), $conf), $conf);
	}
}
If I had to use the "passive MVC" I would never been able to do this.
I think that the View *must* be somehow coupled to the Model by coupling it to a specific Interface. Either it's the Model API or the result object structure, it must be. In this case, (de)coupling can be easily solved by using an Adapter pattern.