How do I extend the Zend Navigation Menu View Helper?
$view->addHelperPath(
APPLICATION_ROOT . '/library/MyApp/View/Helper/Navigation',
'MyApp_View_Helper_'
);
echo $this->navigation()->myMenu(); // name of your class
From: Getting Zend_Navigation menu to work with jQuery's Fisheye
EDIT
Sorry I've not seen your solution, it is exactly what I've posted.
But why this is not a trully extension of menu class?
Zend Menu extend
My code in the plugin file(ROOT/Application/SubmenuPlugin.php):
$view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view');
$submenuPartial = array('submenus/'.$currentControllerName.'.phtml', 'default'); //$currentControllerName defined a couple of lines ago
$view->addHelperPath(APPLICATION_ROOT . '/library/Pcw/View/Helper', 'Pcw_View_Helper_');
$view->navigation()->submenu()->setPartial($submenuPartial);
Location submenus: ROOT/Application/views/scripts/submenus/
Location submenu view helper: ROOT/library/Pcw/View/helper/Submenu.php
Did this help you out?
How to Extend Zend View Properly
Ahh!! Sorted it out. In the view resource, I needed to set the view for the ViewRenderer, as follows:
$viewRenderer = Zend_Controller_Action_HelperBroker
::getStaticHelper('ViewRenderer');
$viewRenderer->setView($this->_view);
(It's in the Resources section of the manual!) Anyhow, that's all I had to do. In order to do its work, the layout looks for the view registered with the renderer...
ZF2 - overriding navigation menu view helper function
Check out this tutorial by Samsonasik. I use a hack of his example to develop two-dimensional menus. While the meat of the tutorial is about dynamic menus, how he renders the menu may be of help.
Samsonasik calls the menu like this:
<div class="nav-collapse">
<?php echo $this->navigation('Navigation')->menu()->setUlClass('nav'); ?>
</div>
In my hack, I call my menu like this:
<?php
// ...
echo "<div class='collapse navbar-collapse'>";
echo "<ul class='nav navbar-nav'>";
echo $this->navigation('mainNavigation')
->menu()
->setPartial('partial/menu')
->render();
echo "</ul>";
echo "</div>";
Injecting custom navigation using a View Helper through the ServiceManager
There is no need to extend the navigation container Zend\Navigation\Navigation
or extend the builtin view helpers to render menu's.
A container manages all pages in the navigation structure. The are several ways to create a container.
All the view helpers (menu, breadcrumbs) use the container as the provider for navigation data. You can eighter set a new container on the view helper using setContainer()
. Alternatively you could just call the view helper in your view without a container setup and the view helper will create a new empty container for you.
If you need some alternate rendering because the default view helpers don't provide it you can create you own navigation view helper.
namespace MyNamespace\View\Helper\Navigation;
use Zend\View\Helper\Navigation\AbstractHelper;
class MyHelper extends AbstractHelper
{
}
Next register your view helper to the navigation pluginManager. I think you can do something like this (untested):
class Module
{
public function onBootstrap($e)
{
$application = $e->getApplication();
/** @var $serviceManager \Zend\ServiceManager\ServiceManager */
$serviceManager = $application->getServiceManager();
$pm = $serviceManager->get('ViewHelperManager')->get('Navigation')->getPluginManager();
$pm->setInvokableClass('myHelper', 'MyNamespace\View\Helper\Navigation\MyHelper');
}
}
Now call you custom helper in your view:
$this->navigation()->myHelper()
How to extend/replace default action helper in Zend Framework
Check out Zend_Controller_Action_HelperBroker. In your bootstrap file try this:
public function _initActionHelpers()
{
$this->bootstrap('frontController')
Zend_Controller_Action_HelperBroker::addHelper($myHelperClass);
}
If you override the getName() behaviour your helper should be called if you refer to the redirector.
Related Topics
Sending/Displaying a Base64 Encoded Image
Mysqli - Fetch_Array Error Call to a Member Function Fetch_Array() on a Non-Object MySQLi
Programmatically Determine Whether to Describe an Object with "A" or "An"
Printing Content of a Xml File Using Xml Dom
PHP Generate Dynamic Pdo Insert
How to Avoid "Using Temporary" in Many-To-Many Queries
Admin Product Pages Custom Field Displayed in Cart and Checkout
MySQL Pdo Name-Value Prepared Statement Using Last Parameter Only
Laravel Eloquent Orm Transactions
Use Keyword in Functions - PHP
Auto Increment Skipping Numbers
Destroy Session on Window Close
Get Number of Rows Matched by Update Query with PHP MySQLi
How to I Send Data from JavaScript to PHP and Vice Versa
PHP Optional Parameters - Specify Parameter Value by Name