Welcome Guest, Not a member yet? Register   Sign In
Order resource route in routes.php
#4

(07-15-2018, 01:13 AM)ubeljan Wrote: To clarify and wonder.

Try the following situation.

PHP Code:
/**
 * --------------------------------------------------------------------
 * Route Definitions
 * --------------------------------------------------------------------
 */

// We get a performance increase by specifying the default
// route since we don't have to scan directories.
$routes->add('/''Begin::index');

//  resource
$routes->resource('test');
$routes->resource('test2', ['namespace' => 'App\Controllers\Admin']);

//  Static visitor
$routes->add('a''Begin::a');
$routes->add('b''Begin::b');
$routes->add('c''Begin::c');

//  Dynamic visitor
$routes->add('(:any)''Begin::i/$1');
$routes->add('(:any)/(:any)''Begin::i2/$1/$2'); 

1) The recources are loaded after the wildcards
The order above is clearly before
How to change this?

2) The Uri /admin/test/i  will not work because of the wildcards.
( The controller is there and works with no wild card present. )

Only the wild cards only cover 2 segments not 3.
In Codeigniter 3 this works, but not in Codeigniter 4?

3) Adding slashes didn't change anything.
The adding of leading slashes is even discouraged when reading a couple forum threads.

So even more questions or are these bugs?

Greetings,
Ubel Jan van Wijhe

Here is the important stuff in config/Routes.php

And the Online Temporary Test Site I am currently working. I have not been able to get Pagination to work so created my own - which leaves a lot to be desired Sad

https://johns-jokes.cf/

PHP Code:
$routes->setDefaultNamespace('App\Controllers');
# $routes->setDefaultController('C_Todo');
$routes->setDefaultController('C_Base');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
$routes->setAutoRoute(true);
$routes->discoverLocal(false);

/**
 * --------------------------------------------------------------------
 * Route Definitions
 * --------------------------------------------------------------------
 */
 
// We get a performance increase by specifying the default
// route since we don't have to scan directories.
# $routes->add('/',                             'C_Home::index');
# $routes->add('/home',                     'C_Home::index');


$routes->add('/base'      'C_Base::index');
$routes->add('/home'      'C_Home::index');
$routes->add('/welcome'   'C_Home::welcome');

$routes->add('/todo'      'C_Todo::index');
$routes->add('/'          'C_Todo::index');
$routes->add('/blogs',         'C_Blogs::index');

$novels = [
 
 'revenge-season',
 
 'fear-and-loathing-in-pattaya',
 
 'general-trinh-is-delivering-papers',
];
foreach(
$novels as $novel):
 
 # http://localhost/revenge-season?page=3
 
 $routes->add('/'.$novel .'/(:any)''C_Novels::chapter');
 
 $routes->add('/'.$novel           'C_Novels::novel');
endforeach; 
 
$routes
->add('/novels'    'C_Novels::index');

$routes->add('/ambasense' 'C_Whoops::ambasense');

# CATCHALL
$routes->add('/(:any)',            'C_Whoops::index'); 
Reply


Messages In This Thread
Order resource route in routes.php - by ubeljan - 07-14-2018, 01:52 AM
RE: Order resource route in routes.php - by John_Betong - 07-15-2018, 02:39 AM



Theme © iAndrew 2016 - Forum software by © MyBB