Another example. Is it ok to access the request object in the view helper
like this? Or is there a better way?

I just need some conformation I am on the right track:

<?php

class App_View_Helper_Navigation extends Zend_View_Helper_Abstract
{

    public function navigation() {

        $ctrl = Zend_Controller_Front::getInstance();
        $module = $ctrl->getRequest()->getModuleName();

        if ( 'admin' != $module ) {
            return $this->view->render('navigation.phtml');
        } else {
            return $this->view->render('admin_navigation.phtml');
        }

    }

}

As always, thanks a lot!

J

On Tue, Apr 14, 2009 at 5:06 PM, J DeBord <[email protected]> wrote:

> I've been plugging away and I may have finally got it.
>
> Take this for example:
>
> I have a model that returns an array.
>
> I have a view helper that initializes the model and then calls for the
> model to return the array: class App_View_Helper_Sidebar extends
> Zend_View_Helper_Abstract
>
> I have a partial that uses the array to render HTML: sidebar.phtml
>
> In my layout.phtml script I am using the following code to pull it all
> together:
>
> <?= $this->partial('sidebar.phtml', array('sidebar' => $this->sidebar()));
> ?>
>
> Is this the best way to access the model from the view? Does it work this
> way whether accessing the model from your Layout Script or an ordinary view
> script (index.phtml for indexAction, etc.)
>
> If I am not on the right track, please advise.
>
> Cheers,
>
> J
>
>
> On Tue, Apr 14, 2009 at 1:49 PM, J DeBord <[email protected]> wrote:
>
>> That was great. Thanks for the article.
>>
>> So, as usual, I took one step forward and two steps back. I thought I had
>> figured it out by making a sidebar controller, navigation controller etc,
>> but it seems I was mislead by the all the evil FSUC authors. But it is a lot
>> of fun.
>>
>> So with that being said, I am back to square one. How do I place echo
>> $this->sidebar into my layout script and have it called without using
>> controllers. How does the framework know what to do when the view sees echo
>> $this->sidebar without any other hints? Is this where a view partial comes
>> into play? Do I need a view helper to take care of tying all the elements of
>> the sidebar together and assigning meaning to $this->sidebar?
>>
>> Thanks a lot.
>>
>>
>>
>> On Tue, Apr 14, 2009 at 7:13 AM, swilhelm <[email protected]> wrote:
>>
>>>
>>> You may wish to read this very interesting
>>>
>>> http://blog.astrumfutura.com/archives/373-The-M-in-MVC-Why-Models-are-Misunderstood-and-Unappreciated.html
>>> article  by Padraic Brady on Models and their role in the MVC pattern.
>>>
>>> I think the section entitled, "Models are Classes, Controllers are
>>> Processes," is germane to the design of a sidebar. You might consider
>>> implementing your sidebar as a Model or set of Models that are rendered
>>> using View Partials, possibly one Model / View Partial pair per sidebar
>>> feature (e.g. blogroll, ad unit, etc.).
>>>
>>> - Steve W.
>>>
>>>
>>> Jason DeBord wrote:
>>> >
>>> > Thanks for the replies.
>>> >
>>> > I created a SidebarController with a sidebarAction() function. In
>>> > sidebar.phtml I have coded the template for my sidebar. Next, I
>>> registered
>>> > this with the actionstack like this:
>>> >
>>> > $this->_helper->actionStack('nav', 'nav','default');
>>> > $this->_helper->actionStack('sidebar', 'sidebar','default');
>>> >
>>> > This is not a good solution however, because I would have to use the
>>> > actionstack in all of my contollers. I want to control what is in the
>>> > sidebar from the SidebarController.
>>> >
>>> > I think I can code a Front Controller Plugin??? That will take care of
>>> > this
>>> > for me... Maybe?
>>> >
>>> > I'm struggling with this step though. Any advice?
>>> >
>>> > Cheers,
>>> >
>>> > J
>>> >
>>> >
>>> > On Mon, Apr 13, 2009 at 12:38 PM, Vadim Gabriel <[email protected]>
>>> > wrote:
>>> >
>>> >> Hey,
>>> >>
>>> >> Or you could simply overload it.
>>> >>
>>> >> $layout->sidebar = "something here";
>>> >>
>>> >> Vince.
>>> >>
>>> >>
>>> >> On Mon, Apr 13, 2009 at 1:31 PM, lightflowmark
>>> >> <[email protected]
>>> >> > wrote:
>>> >>
>>> >>>
>>> >>> They are placeholders for content to be later inserted into.
>>> >>>
>>> >>> Typically, I think, you would have actions called e.g. sidebarAction
>>> and
>>> >>> navAction.  In each of these you would have a line like
>>> >>>    $this->_helper->viewRenderer->setResponseSegment('sidebar');
>>> >>>
>>> >>>
>>> >>> You would then add these actions to the actionStack, so that on any
>>> >>> request,
>>> >>> these two actions were called in addition to your main action.
>>> >>>
>>> >>> Sorry that's a bit terse, but should help you get started.
>>> >>>
>>> >>>
>>> >>>
>>> >>>
>>> >>>
>>> >>>
>>> >>>
>>> >>> Jason DeBord wrote:
>>> >>> >
>>> >>> >
>>> >>>
>>> http://framework.zend.com/manual/en/zend.layout.quickstart.html#zend.layout.quickstart.example
>>> >>> >
>>> >>> > In the above link, what are <?= $this->layout()->nav ?> and <?=
>>> >>> > $this->layout()->sidebar ?>
>>> >>> >
>>> >>> > Are they view helpers? Would someone point me to a resource
>>> describing
>>> >>> how
>>> >>> > to build one? For example, a template of a sidebar that would be
>>> >>> called
>>> >>> by
>>> >>> > <?= $this->layout()->sidebar ?> .
>>> >>> >
>>> >>> > Thanks.
>>> >>> >
>>> >>> >
>>> >>>
>>> >>> --
>>> >>> View this message in context:
>>> >>>
>>> http://www.nabble.com/What-is-this%3A-%3C-%3D-%24this-%3Elayout%28%29-%3Esidebar--%3E-tp23011364p23020557.html
>>> >>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>> >>>
>>> >>>
>>> >>
>>> >>
>>> >> --
>>> >> Vincent Gabriel.
>>> >> Lead Developer, Senior Support.
>>> >> Zend Certified Engineer.
>>> >> Zend Framework Certified Engineer.
>>> >>
>>> >>
>>> >>
>>> >>
>>> >>
>>> >
>>> >
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/What-is-this%3A-%3C-%3D-%24this-%3Elayout%28%29-%3Esidebar--%3E-tp23011364p23033371.html
>>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>>
>>>
>>
>

Reply via email to