0

在我的 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();
4

1 回答 1

0

restfull 控制器和非 restfull 控制器的路线看看代码对我来说很好

<?php

/*
 * Core Auth  routes file.
 */

$routes->group('api', ['namespace' => 'Modules\Auth\Controllers'], function ($routes) {

    $routes->resource('group', ['filter' => 'authJwt']);
    $routes->resource('permission', ['filter' => 'authJwt']);
    $routes->resource('groupPermission', ['filter' => 'authJwt']);
    $routes->resource('userPermission', ['filter' => 'authJwt']);

    $routes->group('auth', function ($routes) {

        $routes->post('signin-jwt', 'Auth::signInJwt', ['filter' => 'isSignIn']);
        $routes->post('signin', 'Auth::signIn', ['filter' => 'isSignIn']);
        $routes->get('signout', 'Auth::signOut', ['filter' => 'authJwt']);
        $routes->get('is-signin', 'Auth::isSignIn',['filter' => 'authJwt']);


        $routes->post('signup', 'Auth::signUp', ['filter' => 'isSignIn']);
        $routes->post('forgot', 'Auth::forgot', ['filter' => 'isSignIn']);

        $routes->post('reset-password-email', 'Auth::resetPasswordViaEmail', ['filter' => 'isSignIn']);
        $routes->post('reset-password-sms', 'Auth::resetPasswordViaSms', ['filter' => 'isSignIn']);

        $routes->post('activate-account-email', 'Auth::activateAccountViaEmail', ['filter' => 'isSignIn']);
        $routes->post('send-activate-email', 'Auth::sendActivateCodeViaEmail', ['filter' => 'isSignIn']);

        $routes->post('activate-account-sms', 'Auth::activateAccountViaSms', ['filter' => 'isSignIn']);
        $routes->post('send-activate-sms', 'Auth::sendActivateCodeViaSms', ['filter' => 'isSignIn']);

    });

});




于 2022-01-07T14:00:41.233 回答