ZF2网址助手定制添加achnor为angularjs路由器 [英] zf2 URL Helper customization to add achnor for angularjs router

查看:191
本文介绍了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>


解决方案

<击>你有一个理由,你为什么不只是手动定义URL后加锚 URL(...) 。'#/主动

如果你有,试试这个:

 '路线'=&GT; / [:控制器[/:动作[#/:锚]]]',


更新:

我检查路由器和URI和URL的来源,似乎网址的视图助手接受第三个选项片段键,以便尝试这个办法:

 的url('[路径]',阵列([PARAMS]),阵列('片段'=&GT;'/主动'));

的Zend /浏览/助手/网址

<一个href=\"https://github.com/zendframework/zf2/blob/master/library/Zend/Mvc/Router/Http/TreeRouteStack.php#L357\"相对=nofollow>的Zend / MVC /路由器/ HTTP / TreeRouteStack

的Zend / URI /乌里

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>

解决方案

do you have a reason why you are not just adding the anchor manually after the url definition url(...).'#/active' ?

if you have, try this:

'route' => '/[:controller[/:action[#/:anchor]]]',

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/View/Helper/Url

Zend/Mvc/Router/Http/TreeRouteStack

Zend/Uri/Uri

这篇关于ZF2网址助手定制添加achnor为angularjs路由器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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