【发布时间】:2022-01-03 07:03:16
【问题描述】:
在我的 codeigniter4 应用程序中,我遇到了奇怪的路由问题,
在路由配置中我有这样的组路由
$routes->group("admin", function($routes){
$routes->match(['get'],'dashboard','Dashboard::index',[
'as'=>'adm_dash'
]);
//start customer
$routes->get('customer/add','Customer::index',[
'as'=>'adm_cust_add_new'
]);
$routes->get('customer/view','Customer::view',[
'as'=>'adm_cust_view'
]);
$routes->get('customer/manage','Customer::manage',[
'as'=>'adm_cust_manage'
]);
//end customer
//start customer actions
$routes->post('customer/create','Customer::createcustomer',[
'as'=>'adm_cust_create_action'
]);
});
在视图文件中
<form class="m-t-20" method="post" action="<?= route_to('adm_cust_create_action') ?>">
<button type="submit" class="btn btn-success waves-effect waves-light">Submit</button>
....
</form>
当我点击提交按钮时,路由转到admin/dashboard 路由而不是customer/create 路由
我的路由配置如下
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(true);
$routes->set404Override();
$routes->setAutoRoute(false);
$routes->setPrioritize();
【问题讨论】:
-
$routes->setPrioritize(false);您可以随时在控制台查看您的路线:php spark routes
标签: codeigniter routes codeigniter-4 php-8.1