Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 588869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:21:51+00:00 2026-05-13T15:21:51+00:00

Background information: I’m in my admin module, and I created a view helper in

  • 0

Background information:

I’m in my admin module, and I created a view helper in modules/admin/views/helpers/AdminPanel.php. I have a layout plugin that forces my view to use the layout in admin/views/layouts/default.phtml.

I’m trying to access my ACL object to determine whether or not the user has resources in the context of a view helper, and then determine whether to return the admin panel html by parsing a configs/admin-nav.xml or not return anything at all.

I’m calling it in my admin layout like so:

<?php echo $this->AdminPanel(); ?>

And the class code which is blank, which I need to access the acl object in:

class My_View_Helper_AdminPanel extends Zend_View_Helper_Abstract {

public function AdminPanel() {}

}

I tried this:

$acl = Zend_Controller_Action_HelperBroker::getStaticHelper('acl');

But this probably isn’t what I’m looking for as it forces the default module’s views/layouts/default.phtml to load and errors occur.

Here’s my global bootstrap file:

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

    private $_acl = null;
    private $_auth = null;

    protected function _initDoctype() {
    $this->bootstrap('view');
    $view = $this->getResource('view');
    $view->setEncoding('UTF-8');
    $view->doctype('HTML4_STRICT');
    }

    protected function _initAutoload() {
    $autoloader = Zend_Loader_Autoloader::getInstance();
    $autoloader->registerNamespace('KG_');
    $resourceLoader = new Zend_Loader_Autoloader_Resource(
        array(
        'basePath' => APPLICATION_PATH,
        'namespace' => '',
        'resourceTypes' => array(
            'form' => array(
            'path' => 'forms/',
            'namespace' => 'Form_'
            ),
            'model' => array(
            'path' => 'models/',
            'namespace' => 'Model_'
            )
        )
        ));
    return $autoloader;
    }

    protected function _initAclAuth() {
    $this->_acl = new Model_Acl;
    $this->_auth = Zend_Auth::getInstance();
    }

    protected function _initNav() {
    $this->bootstrap('layout');
    $layout = $this->getResource('layout');
    $view = $layout->getView();
    $config = new Zend_Config_Xml( APPLICATION_PATH . '/configs/nav.xml', 'mainNav');
    $navigation = new Zend_Navigation( $config );

    $fc = Zend_Controller_Front::getInstance();
    $fc->registerPlugin( new KG_Controller_Plugin_Acl( $this->_acl, $this->_auth ) );

    $role = $this->_auth->getStorage()->read()->role;

    if ( !$role ) {
        $role = 'guest';
    }

    $view->navigation( $navigation )->setAcl( $this->_acl)->setRole( $role );
    }


    protected function _initEncoding() {
    $fc = Zend_Controller_Front::getInstance();
    $response = new Zend_Controller_Response_Http;
    $response->setHeader('Content-Type','text/html;charset=utf-8', true);
    $fc->setResponse($response);
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:21:51+00:00Added an answer on May 13, 2026 at 3:21 pm

    Your KG_Controller_Plugin_Acl plugin should be taking care of the access logic, not your view. If the user doesn’t have access to the resource, you should error out or redirect the user to somewhere else.

    The layout should be set within the controller. Preferably in the init() method with:

    $this->_helper->layout->setLayout();
    

    It looks like you followed the same or a similar tutorial as I did for Zend_Acl. I’m posting my plugin for reference, which includes the logic to handle access control from within the plugin:

    class App_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
    {
    
        protected $_auth = null;
        protected $_acl = null;
    
        public function __construct(Zend_Auth $auth, Zend_Acl $acl)
        {
            $this->_auth = $auth;
            $this->_acl = $acl;
        }
    
        public function preDispatch(Zend_Controller_Request_Abstract $request)
        {
            if ($this->_auth->hasIdentity()) {
                $identity = $this->_auth->getIdentity();
                $role = $identity->acl_role;
            } else {
                $role = 'guest';
            }
    
            // Mapping to determine which Resource the current
            // request refers to (really simple for this example!)
            $resource = $request->controller;
            $privilege = $request->action;
    
    
            if (!$this->_acl->has($resource)) {
                $resource = null;
            }
    
            // ACL Access Check
            if (!$this->_acl->isAllowed($role, $resource, $privilege)) {
                if ($this->_auth->hasIdentity()) {
                    // authenticated, denied access, forward to /error/permissions
                    $request->setModuleName('default');
                    $request->setControllerName('error');
                    $request->setActionName('permissions');
                } else {
                    // not authenticated, forward to login form
                    $request->setModuleName('default');
                    $request->setControllerName('auth');
                    $request->setActionName('login');
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As usual, some background information first: Database A (Access database) - Holds a table
And if you do, can you give some background information on the implementation and
Background: I have a little video playing app with a UI inspired by the
Background I have a massive db for a SharePoint site collection. It is 130GB
Background I am trying to create a copy of a business object I have
Background information: This application is .NET 4/C# Windows Forms using SQLite as it's backend.
Background information first: We are using a strongly-typed DataSet to manage transaction files. That
Some background information: I am creating a Silverlight WCF RIA Services Project. I started
Some background information. This is a distributed application with multiples nodes. A 'communication' thread
Background: At my company we are developing a bunch applications that are using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.