Welcome Guest, Not a member yet? Register   Sign In
AutoRoutingImproved feature
#1

I just wrote about an issue I am facing in stackoverflow and then remembered this forum.
AutoRoutingImproved feature
Pasting it here for reference.
Newbie to CodeIgniter (4.4) here; I am trying to use autoroutingimproved feature of codeigniter documented here

It mentions that it will not route to home/Foo as home is default route. Ok, then how do I get it to route to Foo() method? It goes on to say to delete Foo() method. In that sense the Home controller isn't expected to have any other methods?

I tried setting up method getFoo(): string and expecting to route via http://mysite/Foo

It gives me error: Cannot access the default controller "\App\Controllers\Home::getFoo"

Note: have used c# routing in the past.

Any ideas?  Please help.
Reply
#2

The basic pattern is "controller/method".
If you want http://mysite/foo, create app/Controllers/Foo.php and define the getIndex() method in it.
Reply
#3

(08-27-2023, 06:36 PM)user44953432 Wrote: In that sense the Home controller isn't expected to have any other methods?

Yes. The Home controller has only {HTTP verb} + Index() methods, like getIndex(), postIndex().
Reply
#4

(08-27-2023, 11:03 PM)kenjis Wrote:     Yes. The Home controller has only {HTTP verb} + Index() methods, like getIndex(), postIndex()
ok, is there a route configuration that I can add to force all these to be methods of Home Controller instead but not defining each method as a route in Routes.php?
Reply
#5

What do you really want to do?
I recommend you create Foo controller for http://mysite/foo
Reply
#6

(08-28-2023, 06:39 PM)kenjis Wrote: What do you really want to do?
I recommend you create Foo controller for  http://mysite/foo

Never mind, I already went ahead with that approach. thanks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB