Okay, well I'll try and explain firstly what I'm trying to achieve.

I have a bunch of database tables, such as 'tags' and 'articles', and basically just needed a quick and easy way to generate admin pages out of them, to allow for adding, editing and deleting.

I've written an abstract class extending Zend_Controller_Action that contains index (list view), new, edit and delete actions. These actions use class variables, that are populated in any descendant classes, variables that hold an instance of the model, and which forms to use, as well as some things for customising and 'decorating' the output.

I've then made a bunch of admin controllers that extend this class and populated the class variables. An example may show this better than I can explain it:

class Admin_TagsController extends My_Controller_Action_Admin
{

    public function init()
    {
      $this->_model = new Tags();
      $this->_new_form_class = 'AdminTagsNewForm';
      $this->_edit_form_class = 'AdminTagsEditForm';

      parent::init();
    }
}

That's the entire controller class and it, along with some fairly generic view scripts, gives me all the basic functionality.

The complexity comes in a bit with the list view, as I needed to generate a tabulated display of whatever is in the rowset. So I have a view helper to handle it. Originally it took the resultant rowset object, which meant it could get right back to the table schema and set up the columns, check which are the primary keys and what data types there are etc..
Great…
but then I wanted to use pagination, originally thinking I'd just tweak my view helper to accept a Zend_Pagination object and rattle through laying out the table. However, unlike a rowset object, you can't get at the database table meta data, so although I could lay out a table, I could not do the fancy things that I had done previously, such as check the column types, display datetimes and timestamps in a friendly manner, as well as highlight the primary key column(s) and so forth.

I've managed this now purely by bundling the table meta data returned by Zend_Db_Table->info() into an array with the pagination object, populated within the controller action, stored in a view variable, and then passed in the view to my view helper.

Not sure how easy that was to follow, but there you go. I'm quite pleased with how it all works actually. I've many ways that I can customise things per controller, if I need to, but that's another can of worms ;)

I'm not for one minute going to say there aren't many better ways, but it makes me smile!

Cheers. N

On 18 Sep 2008, at 21:16, Jason Eisenmenger wrote:

Nick,

So you're writing a new partial for every single pagination on your site? And managing how to set the links in ascending/descending, and what db columns each table column param represents if their names arent synced up?

That's alot of repeat code.

If not I'm curious how you've abstracted it.

Jason


On Thu, Sep 18, 2008 at 12:20 PM, Nick Thornley <[EMAIL PROTECTED]> wrote: Thanks for that, it's an interesting idea, though I'm not sure personally, it feels a little odd deciding those sort of display settings within the model.

Frustrating because the info is there, it's just in a nest of protected class variables.

For now I've just decided to put everything inside an array to keep it together for my view helper. Not very pretty, but it gets the job done, for the time being.

Action:
   $select = $this->_model->select()->order($this->_row_order);
   $paginator = Zend_Paginator::factory($select);
   $paginator->setItemCountPerPage(10);
   $paginator->setCurrentPageNumber($curpage);
   $this->view->model = array(
'info' => $this->_model- >info(),
                                             'paginator' => $paginator
                                            );

Cheers
N


On 18 Sep 2008, at 16:15, Jason Eisenmenger wrote:

Nick,

I was just discussing the paginator adapter with Jurrien. I don't have a direct answer but I have this leftover paste I can send your way to show you what kind of usage I wrapped around it. I may propose it later.

http://pastie.org/274967


Jason

On Thu, Sep 18, 2008 at 11:06 AM, Nick Thornley <[EMAIL PROTECTED]> wrote:
Hi everybody.

I currently have a view helper that constructs a tabulated output of the data contained in Zend_Db_Table_Rowset object, using the tables meta data to determine primary keys etc., for various uses.

I would love to make use of Zend_Paginator, but cannot see any obvious way to get from a Zend_Paginator object back to the database table info.

Does anyone know of an obvious way?

Thanks
Nick




Reply via email to