这是一个简易的路由配置入口, 针对 service, action 做路由重定向
备注: 请全部小写
public function addRoute(string $name, array $data)
需要匹配的service名称:action名称
备注: 这里需要认识两个特殊字符
$data = array('module' => '被替换的模块名称', 'service' => '被替换的service名称', 'action' => '被替换的action名称')
备注: data.module, data.service, data.action 是固定的名称
设置成功返回 true, 设置失败返回 false
如果 service_name 等于 index, 则重定向到新的 service (user) + action (top)
<?php
class Bootstrap
{
public function _initOne($dispatcher)
{
$route = array(
'service' => 'user',
'action' => 'top',
);
$dispatcher->getRouter()->getRoutes();
$dispatcher->getRouter()->addRoute('index:*', $route);
}
}
如果 service_name 等于 news, 则重定向到新的 module (admin) + service (news) + action (list)
<?php
class Bootstrap
{
public function _initOne($dispatcher)
{
$route_news = array(
'module' => 'admin',
'service' => 'news',
'action' => 'list',
);
$dispatcher->getRouter()->getRoutes();
$dispatcher->getRouter()->addRoute('news:*', $route_news);
}
}
如果 service_name 等于 cat, action_name 等于 index, 则重定向到新的 service (cat) + action (order)
<?php
class Bootstrap
{
public function _initOne($dispatcher)
{
$route = array(
'service' => 'cat',
'action' => 'order',
);
$dispatcher->getRouter()->getRoutes();
$dispatcher->getRouter()->addRoute('cat:index', $route);
}
}