• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
codeigniter4 controller name style like UserGroup

#1
I name my controller UserGroup according to codeigniter4 coding style as it says:

Class names and namespaces SHOULD be declared in UpperCamelCase, also called StudlyCaps, unless another form is functionally required.

But when I try my controller on browser as http://localhost/usergroup it gives 404 - File Not Found error.
http://localhost/userGroup works. http://localhost/UserGroup works too. But http://localhost/usergroup doesn't.

Should I change my controller name to Usergroup or url to http://localhost/UserGroup (or http://localhost/userGroup)?
Reply

#2
(11-08-2018, 06:47 AM)obozdag Wrote: I name my controller UserGroup according to codeigniter4 coding style as it says:

Class names and namespaces SHOULD be declared in UpperCamelCase, also called StudlyCaps, unless another form is functionally required.

But when I try my controller on browser as http://localhost/usergroup it gives 404 - File Not Found error.
http://localhost/userGroup works. http://localhost/UserGroup works too. But http://localhost/usergroup doesn't.

Should I change my controller name to Usergroup or url to http://localhost/UserGroup (or http://localhost/userGroup)?
you can add routes.
$routes->add('usergroup','userGroup::index')
Reply

#3
(11-08-2018, 06:47 AM)obozdag Wrote: Should I change my controller name to Usergroup or url to http://localhost/UserGroup (or http://localhost/userGroup)?

If you want to use the auto-routing functionality like previous versions had, then yes, you'll need keep the name as ucfirst and not camel case. The framework has no way of guessing which other letters should be capitalized. So, this is a case where it's functionally required. Smile

But, titounnes is right, you can specify each route. That has some included power and flexibility you won't get from auto-routing.
Support Development  • Practical CodeIgniter 3  • Vulcan - CLI Tools for CI4
Reply

#4
@titounnes and @kilishan thanks for the answers. I will use included power of specifying each route although it is very easy to use auto-routing. Smile
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.