Skip to content

Instantly share code, notes, and snippets.

@jsfgreen
Created October 20, 2012 11:58
Show Gist options
  • Save jsfgreen/3923114 to your computer and use it in GitHub Desktop.
Save jsfgreen/3923114 to your computer and use it in GitHub Desktop.
<p>Below are some helpful links</p>
<?php
#Zend\Debug\Debug::dump($this->navigation('admin_navigation')->getContainer()->getPages()) . '<br /><br />';
#Zend\Debug\Debug::dump($this->navigation('user_navigation')->getContainer()->getPages()); die();
#echo get_class($this->navigation('admin_navigation')->getContainer())->getPages(), '<br />';
#cho get_class($this->navigation('user_navigation')->getContainer())->getPages();
#die();
echo $this->navigation('user_navigation')
->menu()
->setUlClass('subnav')
->setMaxDepth(0)
->setRenderInvisible(false)
->render(), PHP_EOL;
<?php
namespace User\Controller;
use Zend\Mvc\Controller\AbstractActionController,
Zend\View\Model\ViewModel,
Zend\Debug\Debug;
class IndexController extends AbstractActionController
{
/**
* UserTable instance
* @ignore
*/
protected $_model;
/**
* (non-PHPdoc)
* @see \Zend\Mvc\Controller\AbstractActionController::indexAction()
*/
public function indexAction()
{
#$container = $this->getServiceLocator()->get('user_navigation');
#Debug::dump($container); die();
#return new ViewModel(array('subnav' => $container));
return new ViewModel();
}
}
<?php
return array(
'controllers' => array(
'invokables' => array(
'User\Controller\Index' => 'User\Controller\IndexController',
),
),
// The following section is new and should be added to your file
'router' => array(
'routes' => array(
'user' => array(
'type' => 'segment',
'options' => array(
'route' => '/user[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'User\Controller\Index',
'action' => 'index',
)
)
)
)
),
'navigation' => array(
'user' => array(
'change-password' => array(
'label' => 'Change Password',
'route' => 'user',
'action' => 'change-password'
),
'manage-avatar' => array(
'label' => 'Manage Avatar',
'route' => 'user',
'action' => 'manage-avatar'
)
)
),
'view_manager' => array(
'template_path_stack' => array(
'user' => __DIR__ . '/../view',
),
)
);
<?php
namespace User;
use Zend\Mvc\ModuleRouteListener,
Zend\ModuleManager\ModuleManager,
Zend\Mvc\MvcEvent,
Zend\Debug\Debug as Debug;
class Module
{
/**
* Module bootstrap
* @param MvcEvent $e
*/
public function onBootstrap(MvcEvent $e)
{
$e->getApplication()->getServiceManager()->get('translator');
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
}
/**
* Use ServiceManager to inject user into controller
* @return multitype:multitype:NULL |\Admin\UserTable
*/
public function getServiceConfig()
{
return array(
'factories' => array(
'user_navigation' => 'User\Navigation\Service\UserNavigationFactory'
)
);
}
/**
* get config
*/
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
/**
* get autoloader config
*
* @return multitype:multitype:multitype:string
*/
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
)
)
);
}
}
<?php
namespace User\Navigation\Service;
use Zend\Navigation\Service\DefaultNavigationFactory;
/**
* Factory for the user sub navigation
*
* @package User
* @subpackage Navigation\Service
*/
class UserNavigationFactory extends DefaultNavigationFactory
{
/**
* (non-PHPdoc)
* @see \Zend\Navigation\Service\DefaultNavigationFactory::getName()
*/
protected function getName()
{
return 'user';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment