Php ZF2树路由
如何配置ZF2树页面路由 我有多层次的页面。例如:Php ZF2树路由,php,zend-framework2,content-management-system,Php,Zend Framework2,Content Management System,如何配置ZF2树页面路由 我有多层次的页面。例如: contacts contacts/office contacts/office/office1 products products/category1 products/category1/product1 还有更多 我对页面使用一个控制器,对路由使用此配置: 'page' => array( 'type' => 'Literal', 'options' => array(
contacts
contacts/office
contacts/office/office1
products
products/category1
products/category1/product1
还有更多
我对页面使用一个控制器,对路由使用此配置:
'page' => array(
'type' => 'Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\PageController'
)
),
'priority' => -1000,
'may_terminate' => false,
'child_routes' => array(
'name' => array(
'type' => 'Segment',
'options' => array(
'route' => ':sn1[/:sn2[/:sn3[/:sn4[/:sn5[/:sn6]]]]]',
'constraints' => array(
'sn1' => '[a-zA-Z][a-zA-Z0-9]*',
'sn2' => '[a-zA-Z][a-zA-Z0-9]*',
'sn3' => '[a-zA-Z][a-zA-Z0-9]*',
'sn4' => '[a-zA-Z][a-zA-Z0-9]*',
'sn5' => '[a-zA-Z][a-zA-Z0-9]*',
'sn6' => '[a-zA-Z][a-zA-Z0-9]*'
),
'defaults' => array(
'controller' => 'Application\PageController',
'action' => 'page'
)
)
)
)
)
页面操作:
$params = array('sn1', 'sn2', 'sn3', 'sn4', 'sn5', 'sn6');
$names = array();
foreach ($params as $param) {
if($this->params($param, NULL) === NULL) {
break;
} else {
$names[] = $this->params($param, NULL);
}
}
var_dump($names);
$path = implode('/', $names);
var_dump($path);
结果如下:
有没有更好的实施方法
array (size=3)
0 => string 'contacts' (length=8)
1 => string 'office' (length=6)
2 => string 'office1' (length=7)
string 'contacts/office/office1' (length=23)