2
votes

I have a controller with a number of views/actions. I am using zend_navigation and breadcrumbs for the main navigation. However when certain views/actions are rendered i want to add a "control panel" with local navigation within this group of views/actions. Adding the panel is no problem it's the logic to decide which view/action i am in.

I can id the view/action from the controller level with

    $controller = $this->getRequest()->getControllerName();
    $action = $this->getRequest()->getActionName();

But can i pass that to the layout, or do i need to or can i detect where i am in the layout? I suppose one option would be to create the views with the control panel in a separate controller but that seems like a dumb way of doing it.

3

3 Answers

1
votes

I think you have to combine what ArneRie and Acherer said:

Inside /application/configs/cp.ini:

cp[] = "moduleA.controllerB.actionC"
cp[] = "moduleA.controllerD.actionE"

Inside your bootstrap:

protected function _initCp()
{
  $ini = new Zend_Config_Ini(APPLICATION_PATH . '/configs/cp.ini');
  Zend_Registry::set('cp', $ini->toArray());
}

Inside your layout:

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

In your partial: /application/layouts/cp.phtml:

<?php
$request = Zend_Controller_Front::getInstance()->getRequest();
$module = $request->getModuleName();
$controller = $request->getControllerName();
$action = $request->getActionName();
if (in_array(implode('.', array($module, $controller, $action)), Zend_Registry::get('cp')) : ?>
    // display cp html here
<?php endif ?>

You might want to double-check the ini array, but this is the path of the Zend Jedi :p

0
votes

Just an idea, i would do this inside an ControllerPlugin

public function preDispatch()
{
    $controller = $this->getRequest()->getControllerName();
    $action = $this->getRequest()->getActionName();

    $layout = Zend_Layout::getMvcInstance();
    $layoutView = $layout->getView();

    $whereIam = $controller. '.' .$action;

    switch ($whereIam) {
        case 'index.showuser':
            $layoutView->showPanel = true;
            $layoutView->controlPanel = $this->view->render('myPanel.phtml');
            break;
        default:
            break;
    }
}


   //layout.phtml
    if ($this->showPanel === true) {
        echo $this->controlPanel;
    }
0
votes

that could work, or just passing a $this->view->cp = true; on the actions that need it, and have a check in the layout.phtml file to see if its set and true