dream07769 2013-09-24 09:14
浏览 21

too long

I am new to zend framwork and I followed based on this link (http://zf2.readthedocs.org/en/latest/tutorials/tutorial.navigation.html) but the breadcrumb doesn't showing in the view or layout. Below are the codes i have implemented. Guide me what i did wrong?

In module.config.php,

return array(
     ........
     'router' => array(
        'routes' => array(
            'admin' => array(
                'type'    => 'segment',
                'options' => array(
                    'route'    => '/admin[/][:action][/:id]',
                    'constraints' => array(
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id'     => '[0-9]+',
                    ),
                    'defaults' => array(
                        'controller' => 'Admin\Controller\Admin',
                        'action'     => 'index',
                    ),
                ),
                'may_terminate' => true,
                 'child_routes' => array(
                    'settings' => array(
                        'type'    => 'Segment',
                        'may_terminate' => true,
                        'options' => array(
                            'route'    => '/general[/][:action][/][:id]',
                            'constraints' => array(
                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'id'     => '[0-9]+',
                            ),
                            'defaults' => array(
                                'controller' => 'Admin\Controller\Settings\General',
                                'action'     => 'index',
                            ),
                        ),
                    ),
                ),
            ),
            'dashboard' => array(
                'type'    => 'segment',
                'options' => array(
                    'route'    => '/admin/dashboard[/][:action][/:id]',
                    'constraints' => array(
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id'     => '[0-9]+',
                    ),
                    'defaults' => array(
                        'controller' => 'Admin\Controller\Dashboard',
                        'action'     => 'index',
                    ),
                ),
            ), 
        ),
    ),
    'navigation' => array(
        'default' => array(
            array(
                'label' => 'Home',
                'route' => 'admin/dashboard',
            ),
            array(
                'label' => 'Admin',
                'route' => 'admin/settings/general/',
                'pages' => array(
                    array(
                        'label' => 'General',
                        'route' => 'admin/settings/general/',
                        'action' => 'index',
                    ),
                    array(
                        'label' => 'Web',
                        'route' => 'admin/settings/general/',
                        'action' => 'web',
                    ),
                ),
            ),
        ),
    ),
'view_manager' => array(
        'template_map' => array(
            'layout/sidemenu'           => __DIR__ . '/../view/admin/common/sidemenu.phtml',  
            'layout/breadcrumbs'           => __DIR__ . '/../view/admin/common/breadcrumbs.phtml', 
            'error/404'               => __DIR__ . '/../view/error/404.phtml',
            'error/index'             => __DIR__ . '/../view/error/index.phtml',
        ),
        'template_path_stack' => array(
            'admin' => __DIR__ . '/../view',
        ),
        'display_not_found_reason' => true, 
        'display_exceptions'       => true,
        'not_found_template'       => 'error/404', 
        'doctype'                  => 'HTML5',
        'exception_template'       => 'error/index',
    ), 
    'service_manager' => array(
        'factories' => array( 
            'navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',  
        ),
    ),
    ......
);

In the layout.phtml

$this->navigation('navigation')
               ->breadcrumbs()
               ->setMinDepth(0)
               ->setPartial('layout/breadcrumbs');
  • 写回答

1条回答 默认 最新

  • douweng5420 2014-04-16 13:23
    关注

    Please change route condition 'admin/dashboard' to 'admin/default'. If it still doesn't work then you can catch the matchedRoute by implementing following code in your module.php :

    /* put these lines on top after namespace */
    
    use Zend\Mvc\ModuleRouteListener;
    
    use Zend\Mvc\MvcEvent;
    
    /* put these functions in class */
    
    public function onBootstrap(MvcEvent $e)
    {
        $eventManager = $e->getApplication()->getEventManager();
        $eventManager->attach('route', array($this, 'onRouteFinish'), -100);
    }
    
    public function onRouteFinish($e)
    {
         $matches    = $e->getRouteMatch();
         $controller = $matches->getParam('controller');
         var_dump($matches);die();
    }
    

    In result, please check the value of ["matchedRouteName":protected] and change your route condition in module.config.php accordingly. Good luck..!!

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度