zf2 URL帮助器自定义为angularjs路由器添加achnor
我在zf2中有以下链接zf2 URL帮助器自定义为angularjs路由器添加achnor,angularjs,zend-framework2,Angularjs,Zend Framework2,我在zf2中有以下链接 <a href="<?php echo $this->url('application/default',array('controller'=> 'enquiries', 'action'=>'index')) ?>"><?php echo $this->translate('Enquiries') ?></a> 将上面的链接转换为 <a href="/application/enquiri
<a href="<?php echo $this->url('application/default',array('controller'=> 'enquiries', 'action'=>'index')) ?>"><?php echo $this->translate('Enquiries') ?></a>
将上面的链接转换为
<a href="/application/enquiries/index">Enquiries</a>
这很好
我正在使用angularjs,它经常使用锚片段。
如何在上述zf2链接url上添加achor“#/active”,使目标url看起来像这样
<a href="/application/bookingenquiries/index#/active">Active Enquiries</a>
您是否有理由不只是在url定义url(…)。#/active'
之后手动添加锚定
如果有,请尝试以下方法:
'route' => '/[:controller[/:action[#/:anchor]]]',
更新:
我检查了路由器、uri和url的源代码,似乎url视图帮助程序接受第三个选项的'fragment'
键,因此请尝试以下操作:
url('[route]',array([params]),array('fragment'=>'/active'));
您有没有理由不只是在url定义url(…).#/active'
之后手动添加锚定
如果有,请尝试以下方法:
'route' => '/[:controller[/:action[#/:anchor]]]',
更新:
我检查了路由器、uri和url的源代码,似乎url视图帮助程序接受第三个选项的'fragment'
键,因此请尝试以下操作:
url('[route]',array([params]),array('fragment'=>'/active'));
您有没有理由不只是在url定义url(…).#/active'
之后手动添加锚定
如果有,请尝试以下方法:
'route' => '/[:controller[/:action[#/:anchor]]]',
更新:
我检查了路由器、uri和url的源代码,似乎url视图帮助程序接受第三个选项的'fragment'
键,因此请尝试以下操作:
url('[route]',array([params]),array('fragment'=>'/active'));
您有没有理由不只是在url定义url(…).#/active'
之后手动添加锚定
如果有,请尝试以下方法:
'route' => '/[:controller[/:action[#/:anchor]]]',
更新:
我检查了路由器、uri和url的源代码,似乎url视图帮助程序接受第三个选项的'fragment'
键,因此请尝试以下操作:
url('[route]',array([params]),array('fragment'=>'/active'));
通过扩展Url创建以下视图帮助程序
namespace Application\View\Helper;
use Zend\View\Helper\Url;
class MyUrl extends Url {
public function __invoke($name = null, $params = array(), $options = array(), $reuseMatchedParams = false) {
if (isset($params['anchor']) && !empty($params['anchor'])) {
$anchor = $params['anchor'];
unset($params['anchor']);
} else {
$anchor = '';
}
$link = parent::__invoke($name, $params, $options, $reuseMatchedParams);
return $link . $anchor;
}
}
在模块文件中,在工厂中添加以下内容以添加新创建的帮助器
public function getViewHelperConfig() {
return array(
'factories' => array(
'myUrl' => function($sm) {
$locator = $sm->getServiceLocator();
$helper = new \Application\View\Helper\MyUrl;
$router = \Zend\Console\Console::isConsole() ? 'HttpRouter' : 'Router';
$helper->setRouter($locator->get($router));
$match = $locator->get('application')
->getMvcEvent()
->getRouteMatch();
if ($match instanceof RouteMatch) {
$helper->setRouteMatch($match);
}
return $helper;
},
),
);
}
在URL中添加锚作为参数
<a href="<?php echo $this->myUrl('application/default',array('controller'=> 'enquiries', 'action'=>'index', 'anchor'=>'#/active')) ?>"><?php echo $this->translate('Enquiries') ?></a>
通过扩展Url创建以下视图帮助程序
namespace Application\View\Helper;
use Zend\View\Helper\Url;
class MyUrl extends Url {
public function __invoke($name = null, $params = array(), $options = array(), $reuseMatchedParams = false) {
if (isset($params['anchor']) && !empty($params['anchor'])) {
$anchor = $params['anchor'];
unset($params['anchor']);
} else {
$anchor = '';
}
$link = parent::__invoke($name, $params, $options, $reuseMatchedParams);
return $link . $anchor;
}
}
在模块文件中,在工厂中添加以下内容以添加新创建的帮助器
public function getViewHelperConfig() {
return array(
'factories' => array(
'myUrl' => function($sm) {
$locator = $sm->getServiceLocator();
$helper = new \Application\View\Helper\MyUrl;
$router = \Zend\Console\Console::isConsole() ? 'HttpRouter' : 'Router';
$helper->setRouter($locator->get($router));
$match = $locator->get('application')
->getMvcEvent()
->getRouteMatch();
if ($match instanceof RouteMatch) {
$helper->setRouteMatch($match);
}
return $helper;
},
),
);
}
在URL中添加锚作为参数
<a href="<?php echo $this->myUrl('application/default',array('controller'=> 'enquiries', 'action'=>'index', 'anchor'=>'#/active')) ?>"><?php echo $this->translate('Enquiries') ?></a>
通过扩展Url创建以下视图帮助程序
namespace Application\View\Helper;
use Zend\View\Helper\Url;
class MyUrl extends Url {
public function __invoke($name = null, $params = array(), $options = array(), $reuseMatchedParams = false) {
if (isset($params['anchor']) && !empty($params['anchor'])) {
$anchor = $params['anchor'];
unset($params['anchor']);
} else {
$anchor = '';
}
$link = parent::__invoke($name, $params, $options, $reuseMatchedParams);
return $link . $anchor;
}
}
在模块文件中,在工厂中添加以下内容以添加新创建的帮助器
public function getViewHelperConfig() {
return array(
'factories' => array(
'myUrl' => function($sm) {
$locator = $sm->getServiceLocator();
$helper = new \Application\View\Helper\MyUrl;
$router = \Zend\Console\Console::isConsole() ? 'HttpRouter' : 'Router';
$helper->setRouter($locator->get($router));
$match = $locator->get('application')
->getMvcEvent()
->getRouteMatch();
if ($match instanceof RouteMatch) {
$helper->setRouteMatch($match);
}
return $helper;
},
),
);
}
在URL中添加锚作为参数
<a href="<?php echo $this->myUrl('application/default',array('controller'=> 'enquiries', 'action'=>'index', 'anchor'=>'#/active')) ?>"><?php echo $this->translate('Enquiries') ?></a>
通过扩展Url创建以下视图帮助程序
namespace Application\View\Helper;
use Zend\View\Helper\Url;
class MyUrl extends Url {
public function __invoke($name = null, $params = array(), $options = array(), $reuseMatchedParams = false) {
if (isset($params['anchor']) && !empty($params['anchor'])) {
$anchor = $params['anchor'];
unset($params['anchor']);
} else {
$anchor = '';
}
$link = parent::__invoke($name, $params, $options, $reuseMatchedParams);
return $link . $anchor;
}
}
在模块文件中,在工厂中添加以下内容以添加新创建的帮助器
public function getViewHelperConfig() {
return array(
'factories' => array(
'myUrl' => function($sm) {
$locator = $sm->getServiceLocator();
$helper = new \Application\View\Helper\MyUrl;
$router = \Zend\Console\Console::isConsole() ? 'HttpRouter' : 'Router';
$helper->setRouter($locator->get($router));
$match = $locator->get('application')
->getMvcEvent()
->getRouteMatch();
if ($match instanceof RouteMatch) {
$helper->setRouteMatch($match);
}
return $helper;
},
),
);
}
在URL中添加锚作为参数
<a href="<?php echo $this->myUrl('application/default',array('controller'=> 'enquiries', 'action'=>'index', 'anchor'=>'#/active')) ?>"><?php echo $this->translate('Enquiries') ?></a>
常规视图帮助程序“url”无法执行此操作,您应该编写自己的视图帮助程序。这可以扩展url视图帮助使用常规视图帮助程序“url”无法做到这一点,您应该编写自己的视图帮助程序。这可以扩展url视图帮助使用常规视图帮助程序“url”无法做到这一点,您应该编写自己的视图帮助程序。这可以扩展url视图帮助使用常规视图帮助程序“url”无法做到这一点,您应该编写自己的视图帮助程序。这可以扩展url视图帮助器您正在使用的zend的witch版本可能已添加到较新版本?您正在使用的zend的witch版本可能已添加到较新版本?您正在使用的zend的witch版本可能已添加到较新版本?您正在使用的zend的witch版本可能已添加到较新版本?