Hi,
I use a sidebar on my current app, displaying random ads, products and stuff. I use an action helper to choose what will be displayed on the sidebar, all 'global logic' is done in the helper and it render the result in a response segment called 'sidebar'.
Then, I just echo $this->layout()->sidebar in my layout.
That's not perfect, I need to call the helper in every action where I want to see something in the sidebar (but it could use a postdispatch hook for mandatory items in sidebar) and the result of the action helper is never used in the action method (it mismatch the purpose of action helpers).
If I have to do that again, I'll use a custom view helper similar to the placeholder but specialised, with a default output and methods to choose what will be displayed in the sidebar and how.
I would use it like that :
//in layout
echo $this->sidebar();
//in actions methods where the sidebar needs to output something else than default
$this->view->sidebar()->setContent(/* array of ordered criteria */);
$this->view->sidebar()->append(/* array of ordered criteria */);
$this->view->sidebar()->prepend(/* array of ordered criteria */);
From: Jachim Coudenys
Sent: Monday, April 26, 2010 10:13 AM
Subject: [fw-mvc] Navigation, sidebar blocks, etc...
Hi,
I'm looking for the best way to include 'sidebar content' into my Zend Framework application.
I fixed the navigation problem, by setting it up in the bootstrap (ZFv1.10.2) and adding it to the Zend_Navigation registry.
But now I want to add random product blocks in the sidebar of pages, linking to the actual product page in the application.
I've used a custom Zend_Controller_Action class, where I've put 'global logic', and used the ActionStack to forward the request to a navigation action, but that doesn't feel right.
Is the postDispatch hook (helper) the correct place for this?
Regards,
Jachim Coudenys
没有评论:
发表评论