Zend Action Helper vs. Plugin

I have a sidebar that appears on every page. The first elements of the sidebar are: a) the login form or b) information about the current user (depending on whether the user is logged in or not).

I read several ways to do this and plan to initialize the sidebar in bootstrap.

When it comes to adding user data or a login form in the sidebar, should I do this from pre-submission in the action assistant? Or from pre-sending to the controller plugin? Why?

Thank!

+4
source share
4 answers

' (ZF Lead).

public function preDispatch() Action Helper /User-Widget.

+1

ActionStack , . Stacking , , , .

( Auth, ), / ). $this->_helper->viewRenderer->setResponseSegment('myusersidebar');, Zend_Layout <?= $this->myusersidebar ?> -.

, ( Action Stack - ), , Zend MVC .

, (, ajax-, , , ). , ( ajax), , Ajax (, Zend_Layout AjaxContext).

"" , html- , ( ajax, PDF ..).

0

I really think it's like it's NOT DRY. The user object will already be in the ZF application (Zend_Auth), therefore, additional duplicate logic is not needed by IMO. All that remains is your opinion in order to decide what to display based on the status of the object.

Oh, I highly recommend partial for this.

eg. in your layout:

<?= $this->partial('userSidebar.phtml'); ?>

and then in your partial /application/layouts/userSidebar.phtml:

<div id="sidebar">
<?php if Zend_Auth::getInstance()->hasIdentity() : ?>
  <?php $user = Zend_Auth::getInstance()->getIdentity() ?>
  // do some user profiling stuffies
  // if you need more information you should rather associate the user with those entities (else consider retrieving here or passing it as a parameter in the partial method)
<?php else : ?>
  // not logged in
  // do some login/registering stuffies
<?php endif ?>
</div>
0
source

I would use view helpers. This is from my first Zend project. It draws a link, depending on whether the user is an administrator.

<?php
class TBB_View_Helper_PanelLink extends Zend_View_Helper_Abstract
{
    public function panelLink($moduleName = 'customer')
    {
        $panelLink = "";
        $auth = Zend_Auth::getInstance();
        if($auth->hasIdentity()) {
            $identity = $auth->getIdentity();
            $username = $identity->username;
            $userModel = new TBB_Model_Users();
            $userID = $userModel->getUserIDByUsername($username);
            if($userModel->isAdminUser($userID)) {
                if($moduleName == 'customer') {
                    $panelLink =  '<a class="span-4" href="admin/">Admin Panel</a>';
                } else if($moduleName == 'admin') {
                    $panelLink = '<a class="span-4" href="/">Homepage</a>';
                }
            }
        }
        return $panelLink;
    }
}
0
source

All Articles