Welcome Guest, Not a member yet? Register   Sign In
Controller & Model Name
#1

Hello,
It's me again!
Sorry, I ask a lot of questions to make the best use of CI4.

On this page: https://codeigniter4.github.io/CodeIgnit...llers.html, it says "ONLY the first character can be uppercase"

However, if I use the CLI command "--suffix", the controller name is called "MynameController"

So:
- is it correct to use the word "Controller" in the controller name?
- same for Models. Should we use the word "Model" in the model name (e.g. MynameModel)?

If you can tell me more about the best practices for naming files, I'm interested Smile

I think it would be nice to add this to the documentation as I seem to have seen other posts on the forum already.

Thanks in advance for your anwser
--- I am not a developer ---
Reply
#2

What you cited refers to auto-routing controllers.
The autorouter requires consistency in controller names.

If you define the routes yourself, then it doesn't matter what the name of the controller is.
The suffix is used to prevent class name conflicts. But it is not required, as, for example, when importing a model before a class declaration, you can assign an alias.
PHP Code:
// names conflict
use Model\User;
class 
User {} 
Reply
#3

(06-27-2022, 10:17 AM)InstantT Wrote: I think it would be nice to add this to the documentation as I seem to have seen other posts on the forum already.

I sent a PR.
https://github.com/codeigniter4/CodeIgniter4/pull/6191
Reply
#4

The note is added.
https://codeigniter4.github.io/CodeIgnit...controller
Reply
#5

Hi!

I agree about to have the best practices for naming files in the documentation!!
TIA!
Reply
#6

Yes, it would be nice to have best practices for naming files, but also the names of classes, variables etc.

Ex. https://webdevetc.com/blog/laravel-naming-conventions/ (for Laravel)
--- I am not a developer ---
Reply




Theme © iAndrew 2016 - Forum software by © MyBB