Php 带有可选子域的zf2分页
我很难使用ZF2路由和分页。 我的路由配置如下:Php 带有可选子域的zf2分页,php,routing,pagination,zend-framework2,Php,Routing,Pagination,Zend Framework2,我很难使用ZF2路由和分页。 我的路由配置如下: 'router' => array( 'routes' => array( 'website' => array( 'type' => 'Hostname', 'options' => array( 'route' => '[:subdomain]foo.local', '
'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')); ?>
您将子域路由参数的默认值设置为“www.”。将其留空,以保留当前正在使用的内容,或者如果您希望在URL生成过程中使用其他内容,则可以使用所需的值传递该路由参数
$this->url($this->route,array('page'=>$this->previous),array(),true);?>代码>
简直成了
$this->url($this->route,array('page'=>$this->previous,'subdomain'=>'test'),array(),true);?>代码>请将您的分页控制模板也包括在内好吗?我认为您可能需要在url视图助手调用中设置$reuseMatchedParams
标志。请看:嗨,克里斯普,谢谢你的帮助:我用编码更新了帖子,我没有使用$reuesMatchedParams,我尝试添加它,但不幸的是没有任何改变:(你找到答案了吗?
<?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); ?>">‹</a></li>
<?php else: ?>
<li><a href="#" class="disabilitato">‹</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); ?>">›</a></li>
<?php else: ?>
<li><a href="#" class="disabilitato">›</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',
),
),
),