Hi,
I've been reading a number of articles about why the Action Stack is bad and
everything you need to achieve with the action stack could be achieved with
ViewHelpers.
I completely buy into this... I can't remember the number of times I've had
to fudge code because my predispatch hooks are being caled over and over
depending on how many things are in the action stack. I wish i'd read these
articles 12 months ago.
So I just have a couple of questions about ViewHelpers, Lahyout and URL
parameters.
Zend_Layout is great, full control over layout of the whole application.
Just spit out your main content via <?php echo $this->layout()->content; ?>
But what I can gather from the articles is that if I want to display a left
hand menu, which perhaps lists 'posts' based on a date from the URL, then I
should write a ViewHelper. Lets call it My_View_Helper_LeftNav();
Its in the left hand of my Layout so in the layout I'm just spitting it out
in my layout script e.g. <?php echo $this->LeftNav(); ?>
The articles suggest that its fine to allow read access to models from the
View via the ViewHelper. So basically all I need to do is grab the date
from the URL and send it to the Model via the ViewHelper. I can then spit
out the results.
And thats the problem... how do I access the date from the URL? How do I get
the request object? Would you get it via the front controllers like this?
Class My_View_Helper_LeftNav()
{
public function LeftNav()
{
$front = Zend_Controller_Front::getInstance();
$request = $front->getRequest();
$date = $request->getParam('date');
}
What would be the recommended method to access URL parameters directly via a
ViewHelper?
Remember I can't communicate it via the Controller because the Controller
is only dealing with the main content and I'm trying to achieve Fat
model/Thin Controller approach and doing away with the action stack.
In the past I've used the action stack, inserted code into the layout using
a <?php echo $this->layout()->leftNav; ?> placeholder and then set the
response segment in the action via <?php
$this->_helper->viewRenderer->setResponseSegment(leftNav); ?>
With the Layout/ViewHelper approach is the setResponseSegment pretty much
redundant?
Cheers,
Sam
P.S. here is one of the articles I was reading:
http://www.rmauger.co.uk/2009/03/why-the-zend-framework-actionstack-is-evil/
--
View this message in context:
http://www.nabble.com/Actionstack-bad%2C-Layout-and-View-Helpers-good---tp24474375p24474375.html
Sent from the Zend Framework mailing list archive at Nabble.com.