Php 使用KNP菜单中的RegexVoter仅设置当前一项
我像这样使用KNP菜单中的regexVoterPhp 使用KNP菜单中的RegexVoter仅设置当前一项,php,symfony,knpmenubundle,knpmenu,Php,Symfony,Knpmenubundle,Knpmenu,我像这样使用KNP菜单中的regexVoter //This is on my createMenuAction $this->matchingRoute($menu); /** * @param $menu * * @return bool */ private function matchingRoute($menu) { foreach ($menu->getChildren() as $child) { $childRegex = $chil
//This is on my createMenuAction
$this->matchingRoute($menu);
/**
* @param $menu
*
* @return bool
*/
private function matchingRoute($menu)
{
foreach ($menu->getChildren() as $child) {
$childRegex = $child->getAttribute('regex');
$voter = new RegexVoter($childRegex);
$voterTest = $voter->matchItem($child);
if ($voterTest == true && $this->request->getUri()) {
$child->setCurrent(true);
} else {
$child->setCurrent(false);
}
}
}
这是可行的,但将当前类设置为具有正则表达式属性的所有子类。这名选民将childs regex与他们的路线进行比较,因此它始终成为现实
我试图添加returntrue
但这会将当前类设置为使用regexVoter返回true的第一个孩子
我是否应该与此投票者对照当前路线检查此正则表达式
如何使用此投票者设置好孩子的当前类别
谢谢
if ($voterTest == true && $this->request->getUri()) {
$child->setCurrent(true);
return true;
} else {
$child->setCurrent(false);
}