zf2导航痕迹分页 [英] zf2 navigation breadcrumbs paging

查看:107
本文介绍了zf2导航痕迹分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

找不到正确的方法来描述适用于面包屑的站点地图。



例如,我在 module.config.php

 导航 => array(
'default'=> array(
array(
'label'=>'Home',
'route'=>'home'
),
array(
'label'=>'Articles,
'route'=>'articles,
'pages'=> array(
array(
'label'=>'Paging',
'route'=>'articles,
'id'=>'articles,
'pages'=> array(
array(
'label'=>'Page 1',
'route'=>'1'
),
array(
'label'=>'Page 2',
'route'=>'2'

...




),
),

我的意思是应该匹配 articles / page / 1 articles / page / 2 ...



路由位于 autoload / routes.global.php

 'articles'=> array(
'type'=>'Zend\Mvc\Router\Http\Literal',
'options'=> array(
'route'=> '/ articles',
'defaults'=> array(
'controller'=>'Articles\Controller\Index',
'action'=>'index' ,
),
),
'may_terminate'=>是,
'child_routes'=> array(
'pagination'=> array(
'type'=>'Segment',
'options'=> array(
'route'=>'/ page [/:page]',
'约束'=> array(
'page'=>'[0-9A-Za-z] +',
),
'defaults'=> array(
'controller'=>'Articles\Controller\Index',
'action'=>'index',
),
),
),
),
),

我需要进行动态面包屑分页。
所以我尝试从控制器中添加示例页面

  $ navi = $ this-> getServicelocator()-> ; get('Navigation'); 
$ page = $ navi-> findById(’articles’);
$ page-> addPage(
array(
'label'=>'Page 10',
'route'=>'10'

);

面包屑在 articles / page / 10 是空的?我这样做不是正确的方法吗?

解决方案

您必须以这种方式更改导航(页面数组)空):

 '导航'=> array(
'default'=> array(
array(
'label'=>'Home',
'route'=>'home'
),
array(
'label'=>'Articles,
'route'=>'articles,
'pages'=> array(
array(
'label'=>'Paging',
'route'=>'articles,
'id'=>'articles,
'页面'=> array()



),

然后,在控制器操作中,您必须添加以下代码:

  $ navigation = $ this-> getServiceLocator()-> get('Navigation'); 
$ page = $ navigation-> findBy('id','article');
$ page-> addPage(array(
'uri'=> $ this-> getRequest()-> getRequestUri(),
'label'=>'Page'。$ pageNumber,
'active'=> true,
));

就像那样,所有页面无线

Cannot find the right way to describe sitemap that works with breadcrumbs.

For example i have a navigation described in module.config.php

'navigation' => array(
    'default' => array(
        array(
            'label' => 'Home',
            'route' => 'home'
        ),
        array(
            'label' => 'Articles',
            'route' => 'articles',
            'pages' => array(
                array(
                    'label' => 'Paging',
                    'route' => 'articles',
                    'id' => 'articles',
                    'pages' => array(
                        array(
                            'label' => 'Page 1',
                            'route' => '1'
                        ),
                        array(
                            'label' => 'Page 2',
                            'route' => '2'
                        )
                        ...
                    )
                )
            )
        )
    ),
),

And there i mean it should match patterns like articles/page/1 and articles/page/2 ...

The routes are in autoload/routes.global.php

'articles' => array(
    'type' => 'Zend\Mvc\Router\Http\Literal',
    'options' => array(
        'route'    => '/articles',
        'defaults' => array(
            'controller' => 'Articles\Controller\Index',
            'action'     => 'index',
        ),
    ),
    'may_terminate' => true,
    'child_routes' => array(
        'pagination' => array(
            'type'    => 'Segment',
            'options' => array(
                'route'       => '/page[/:page]',
                'constraints' => array(
                    'page'       => '[0-9A-Za-z]+',
                ),
                'defaults'    => array(
                    'controller' => 'Articles\Controller\Index',
                    'action'     => 'index',
                ),
            ),
        ),
    ),
),

I need to make dynamic breadcrumb paging. So i tried to add example page from controller

$navi = $this->getServicelocator()->get('Navigation');
$page = $navi->findById('articles');
$page->addPage(
    array(
        'label'  => 'Page 10',
        'route' => '10'
    )
);

Breadcrumbs were empty at articles/page/10 ? Is not the right way i am doing this ?

解决方案

You have to change your "navigation" this way ("pages" array empty) :

'navigation' => array(
'default' => array(
    array(
        'label' => 'Home',
        'route' => 'home'
    ),
    array(
        'label' => 'Articles',
        'route' => 'articles',
        'pages' => array(
            array(
                'label' => 'Paging',
                'route' => 'articles',
                'id' => 'articles',
                'pages' => array()
            )
        )
    )
),

Then, in your controller action you have to add this code :

$navigation = $this->getServiceLocator()->get('Navigation');
$page = $navigation->findBy('id', 'article');
$page->addPage(array(
    'uri' => $this->getRequest()->getRequestUri(),
    'label' => 'Page ' . $pageNumber,
    'active' => true,
));

Like that, all your pages will have their name into the breadcrumb and not a generic term.

这篇关于zf2导航痕迹分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆