Skip to content

Instantly share code, notes, and snippets.

@jsfgreen
Created October 20, 2012 11:58

Revisions

  1. @invalid-email-address Anonymous revised this gist Oct 20, 2012. 1 changed file with 59 additions and 0 deletions.
    59 changes: 59 additions & 0 deletions admin.phtml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    <?= $this->doctype(); ?>

    <html lang="en">
    <head>
    <meta charset="utf-8">
    <?php
    echo $this->headTitle('ZF2 '. $this->translate('Skeleton Application'))
    ->setSeparator(' - ')->setAutoEscape(false), PHP_EOL;
    echo $this->headMeta()->appendName('viewport', 'width=device-width, initial-scale=1.0'), PHP_EOL;
    echo $this->headLink(array(
    'rel' => 'shortcut icon',
    'type' => 'image/vnd.microsoft.icon',
    'href' => $this->basePath() . '/images/favicon.ico'
    ))
    ->prependStylesheet($this->basePath() . '/css/bootstrap-responsive.min.css')
    ->prependStylesheet($this->basePath() . '/css/style.css')
    ->prependStylesheet($this->basePath() . '/css/bootstrap.min.css');
    ?>
    </head>
    <body>

    <div class="navbar navbar-fixed-top">
    <div class="navbar-inner">
    <div class="container">
    <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    </a>
    <a class="brand" href="<?= $this->url('home'); ?>"><?= $this->translate('Skeleton Application'); ?></a>
    <div class="nav-collapse">
    <?php
    echo $this->navigation('admin_navigation')
    ->menu()
    ->setUlClass('nav')
    ->setMaxDepth(0)
    ->setRenderInvisible(false), PHP_EOL;
    ?>
    </div><!-- .nav-collapse -->
    </div>
    </div>
    </div>

    <div class="container">
    <?= $this->content; ?>
    <hr>
    <footer>
    <p>&copy; 2012 Chuck Norris. <?php echo $this->translate('All rights reserved.') ?></p>
    </footer>
    </div> <!-- /container -->

    <?php
    echo $this->inlineScript();
    echo $this->headScript()
    ->prependFile($this->basePath() . '/js/html5.js', 'text/javascript', array('conditional' => 'lt IE 9',))
    ->prependFile('//ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js'), PHP_EOL;
    ?>
    </body>
    </html>
  2. @invalid-email-address Anonymous created this gist Oct 20, 2012.
    28 changes: 28 additions & 0 deletions IndexController.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    <?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();
    }
    }
    59 changes: 59 additions & 0 deletions Module.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    <?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__,
    )
    )
    );
    }
    }
    22 changes: 22 additions & 0 deletions UserNavigationFactory.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    <?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';
    }
    }
    15 changes: 15 additions & 0 deletions index.phtml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    <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;
    47 changes: 47 additions & 0 deletions module.config.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    <?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',
    ),
    )
    );