zf2与可选子域的分页

时间:2014-05-17 15:15:11

标签: php routing pagination zend-framework2

我很难使用ZF2路由和分页。 我正在使用此配置进行路由:

 'router' => array(
    'routes' => array(

        'website' => array(
            'type' => 'Hostname',
            'options' => array(
                'route' => '[:subdomain]foo.local',
                'constraints' => array(
                    'subdomain' => '[www.|test.]'
                ),
                'defaults' => array(
                    'controller'    => 'Frontend\Controller\Index',
                    'action'        => 'index',
                    'subdomain'     => 'www.'
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(

                'homepage' => array(
                    'type'    => 'segment',
                    'options' => array(
                        'route'    => '/',
                        'defaults' => array(
                            'controller' => 'Frontend\Controller\Index',
                            'action'     => 'index',
                        ),
                    ),
                ),
                'structures' => array(
                    'type'    => 'segment',
                    'options' => array(
                        'route'    => '/structures[/:action]',
                        'defaults' => array(
                            'controller' => 'Frontend\Controller\Structures',
                            'action'     => 'index',
                        ),
                    ),
                ),
                [...]
                'frontend_blog' => array(
                    'type'    => 'segment',
                    'options' => array(
                        'route'    => '/blog[/:page]',
                        'constraints' => array(
                            'page' => '[0-9]+'
                        ),
                        'defaults' => array(
                            'controller' => 'Frontend\Controller\Blog',
                            'action'     => 'index',
                        ),
                    ),
                ),
                'frontend_single' => array(
                    'type'    => 'segment',
                    'options' => array(
                        'route'    => '/blog/view/[:id]',
                        'defaults' => array(
                            'controller' => 'Frontend\Controller\Blog',
                            'action'     => 'view',
                        ),
                    ),
                ),
                'frontend_bycategory' => array(
                    'type'    => 'segment',
                    'options' => array(
                        'route'    => '/blog/category/[:id]',
                        'defaults' => array(
                            'controller' => 'Frontend\Controller\Blog',
                            'action'     => 'category',
                        ),
                    ),
                ),
                'frontend_news' => array(
                    'type'    => 'segment',
                    'options' => array(
                        'route'    => '/news[/:page]',
                        'constraints' => array(
                            'page' => '[0-9]+'
                        ),
                        'defaults' => array(
                            'controller' => 'Frontend\Controller\News',
                            'action'     => 'index',
                        ),
                    ),
                ),
                [...]
            ),
        ),
    ),
),

也就是说,我希望foo.local可用作www.foo.local,test.foo.local或foo.local:实际上它工作正常。困难的部分带有分页视图助手:如果我这样使用它:

 <?php echo $this->paginationControl($this->list, 'Sliding', 'frontend/pagination_control', array('route' => 'website/frontend_blog')); ?>

它始终输出为链接foo.local / blog / 2,而我更喜欢它保留www或测试我是否访问www.foo.local / blog或test.foo.local / blog。 我做错了什么?

也许有用的解释我有一个相同的移动路由配置,这就是我'使用'网站'子路由容器。 谢谢。 甲

@Crisp: 以下是frontend_paginationcontrol的内容:

 <?php if ($this->pageCount > 1): ?>

<nav id="paginazione">
    <ul>
        <?php if (isset($this->previous)): ?>
            <li><a href="<?php echo $this->url($this->route, array('page' => $this->previous), array(), true); ?>">&#8249;</a></li>
        <?php else: ?>
            <li><a href="#" class="disabilitato">&#8249;</a></li>
        <?php endif; ?>
        <li><a href=""><?php echo $this->current; ?></a></li>
        <li>di</li>
        <li><a href=""><?php echo $this->pageCount ?></a></li>
        <?php if (isset($this->next)): ?>
            <li><a href="<?php echo $this->url($this->route, array('page' => $this->next), array(), true); ?>">&#8250;</a></li>
        <?php else: ?>
            <li><a href="#" class="disabilitato">&#8250;</a></li>
        <?php endif; ?>
    </ul>
</nav>

我按照你的建议尝试但不改变结果:(

更新:实际上问题似乎是由设置子域的默认值引起的,使用此配置它可以正常工作(这是模块

website' => array(
            'type' => 'Hostname',
            'options' => array(
                'route' => '[:subdomain.]foo.local',
                'constraints' => array(
                    'subdomain' => '(www|test)'
                ),
                'defaults' => array(
                    'controller'    => 'Frontend\Controller\Index',
                    'action'        => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(

                'homepage' => array(
                    'type'    => 'segment',
                    'options' => array(
                        'route'    => '/',
                        'defaults' => array(
                            'controller' => 'Frontend\Controller\Index',
                            'action'     => 'index',
                        ),
                    ),
                ),

1 个答案:

答案 0 :(得分:0)

您将子域路由参数的默认值设置为“www。”。将其留空,以保留当前正在使用的内容,或者如果您希望在URL生成期间使用其他内容,则可以使用所需的值传递该路由参数。

$this->url($this->route, array('page' => $this->previous), array(), true); ?>

简单地变成

$this->url($this->route, array('page' => $this->previous, 'subdomain' => 'test'), array(), true); ?>

相关问题