本文介绍了ZF2网址助手定制添加achnor为angularjs路由器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下链接在ZF2
< A HREF =< PHP的echo $这个 - > URL('应用程序/默认,阵列('控制'=>'查询','行动'=>'指数'))>>< PHP的echo $这个 - >翻译('查询')>< / A>
和该路由器在ZF2
'应用'=>阵列(
'型'=> '文字',
'选项'=>阵列(
'路线'=> '/应用',
'缺省'=>阵列(
__NAMESPACE__'=> 应用程序\\控制器,
控制器=> '指数',
'行动'=> '指数',
)
)
may_terminate'=>真正,
child_routes'=>阵列(
默认=>阵列(
'型'=> '分割',
'选项'=>阵列(
'路线'=> / [:控制器[/:行动]]',
'限制'=>阵列(
控制器=> [A-ZA-Z] [A-ZA-Z0-9 _-] *',
'行动'=> [A-ZA-Z] [A-ZA-Z0-9 _-] *',
)
'缺省'=>阵列(
)
)
)
)
)
这上面的转换成链接
< A HREF =/程序/查询/索引>查询及LT; / A>
这是罚款。
我使用angularjs,它采用锚碎片很多。
如何添加亚割#/主动上面ZF2链接URL,这样的目标URL是这个样子。
< A HREF =/应用/ bookingenquiries /指数#/主动>活动查询及LT; / A>
解决方案
更新:
我检查路由器和URI和URL的来源,似乎网址的视图助手接受第三个选项片段
键,以便尝试这个办法:
的url('[路径]',阵列([PARAMS]),阵列('片段'=>'/主动'));
的Zend / MVC /路由器/ HTTP / TreeRouteStack
I have a following Link in zf2
<a href="<?php echo $this->url('application/default',array('controller'=> 'enquiries', 'action'=>'index')) ?>"><?php echo $this->translate('Enquiries') ?></a>
and this router in zf2
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/application',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
which convert above link into
<a href="/application/enquiries/index">Enquiries</a>
which is fine.
I am using angularjs, which uses anchor fragments a lot.How can I add achor "#/active" on above zf2 link url, so target url look something like this.
<a href="/application/bookingenquiries/index#/active">Active Enquiries</a>
解决方案
UPDATE:
I checked the source for router and uri and url , it seems that url view helper accepts a 'fragment'
key for the third option so try this :
url('[route]',array([params]),array('fragment'=>'/active'));
Zend/Mvc/Router/Http/TreeRouteStack
这篇关于ZF2网址助手定制添加achnor为angularjs路由器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!