Welcome Guest, Not a member yet? Register   Sign In
Problems with autorouting
#1

(This post was last modified: 02-15-2025, 03:55 PM by 4usol.)

Hi,

since dynamic routes are not allowed in ci4, i try to setup the autorouting (improved) to get nearly the same situation like the ci3 dynamic routes ( i cannot and wont define for every controller own static routes).

So like the docu i do the following steps.

1) App/Routing
Code:
public bool $autoRoute = true;

2) App/Feauture
Code:
public bool $autoRoutesImproved = true;

3) App/Routes.php
Code:
//$routes->get('/', 'Home::index'); //Disabled because autorouting!
//$routes->get('mysubfolder/', '\App\Controllers\mysubfolder\mycontroller::index');//Disabled because autorouting!
 
also i have overwrite the 404error
//Error 404
Code:
$routes->set404Override(function(){ die("test routes set404 > STOPP >".$_SERVER['HTTP_HOST'].' '.$_SERVER['REQUEST_URI']); } );

If i understand it corretly, autorouting only works if there is no single static rule for the controller defined in Routes.php.

(I use the shield-authentification, maybe its important to notice, or not.)

After i do the changes, no page is avivable anymore. I only get my 404-error "test routes set404..."

Before i change it all pages will shows as they should. Now nothing works...

What i do wrong?
Reply
#2

Note:

A controller method that will be executed by Auto Routing (Improved) needs HTTP verb
(get, post, put, etc.) prefix like getIndex(), postCreate().

Check the Routes:
PHP Code:
php spark routes 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 02-16-2025, 10:11 AM by 4usol.)

oh, i dont know that.
Have i define the same function a multiple time if i use it in post/get case etc.?
For example
"postMyEditFunction(){...content}"
"getMyEditFunction(){..copy of postMyEditFunction or can i say here something link "SELF->postMyEditFunction();"}"
"or is there a way to setup multiple names for a single function - 
"postMyEditFunction,
  getMyEditFunction{}"

By the way, is there no other way to handle routes in a more dynamically way?

Maybe there is also a way to add more additional routes by additional files with more routes or add routes to a config array or something else?

I cannot create a complete routing-file with all possible routes of all possible controllers and modules. In CI3 this was no problem, i could use a dynamic route with "(any)", but in CI4 it wont work without a controllername as min, so i need to find a new way without loosing my flexible and dynamic way.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB