CodeIgniter Forums
$routes->match() behavior in 4.4.1 - Printable Version

+- CodeIgniter Forums (
+-- Forum: CodeIgniter 4 (
+--- Forum: CodeIgniter 4 Support (
+--- Thread: $routes->match() behavior in 4.4.1 (/showthread.php?tid=88473)

$routes->match() behavior in 4.4.1 - joho - 09-13-2023

Does $routes->match() behave differently in 4.4.x?

I have this, and it works for 4.3.x, but seemingly not for 4.4.1:

use CodeIgniter\Router\RouteCollection;
use App\Controllers\zAdmin;


$routes->get( '/', [zAdmin::class, 'index'] );

$routes->group( 'zadmin', static function( $routes ) {
    $routes->match( ['get','post'], 'fetchinfo', [zAdmin::class, 'ajax_fetch'] );
    $routes->match( ['get','post'], 'fetchrepoinfo', [zAdmin::class, 'ajax_fetch_repo'] );
    $routes->match( ['get','post'], 'fetchzampnews', [zAdmin::class, 'ajax_fetch_zamp_news'] );
    $routes->match( ['get','post'], 'tagzampnews', [zAdmin::class, 'ajax_tag_zamp_news'] );
    $routes->match( ['get'], 'zamprepo', [zAdmin::class, 'zamprepo'] );
    $routes->match( ['get'], 'zampnews', [zAdmin::class, 'zampnews'] );
    $routes->match( ['get', 'post'], 'create', [zAdmin::class, 'edit'] );
    $routes->match( ['get', 'post'], 'edit/(:segment)', [zAdmin::class, 'edit'] );
    $routes->match( ['get'], '(:segment)', [zAdmin::class, 'view'] );
    $routes->get( '/', [zAdmin::class, 'index'] );

"Home" work, i.e. no parameters at all, but anything other than that yields a 404 with messages like "Can't find a route for 'get: 2'" (which I think should have been triggered on the second to last match(). I'm obviously doing something wrong, I just don't know what?

Hmm ... apparently this:

$routes->group( 'zadmin', static function( $routes )

needed to be this:

$routes->group( '', static function( $routes )

RE: $routes->match() behavior in 4.4.1 - kenjis - 09-13-2023

Check the routing table.
$ php spark routes

RE: $routes->match() behavior in 4.4.1 - joho - 09-13-2023

(09-13-2023, 03:42 AM)kenjis Wrote: Check the routing table.
$ php spark routes

Yeah, I did that, thanks, and it looked good; until I realized that /zadmin shouldn't be a part of the route. So setting it to '' (empty) worked better Cool