CodeIgniter Forums
Controller & Model Name - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: Controller & Model Name (/showthread.php?tid=82269)



Controller & Model Name - InstantT - 06-27-2022

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/CodeIgniter4/incoming/controllers.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


RE: Controller & Model Name - iRedds - 06-27-2022

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 {} 



RE: Controller & Model Name - kenjis - 06-27-2022

(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


RE: Controller & Model Name - kenjis - 06-27-2022

The note is added.
https://codeigniter4.github.io/CodeIgniter4/cli/cli_generators.html#make-controller


RE: Controller & Model Name - FlavioSuar - 06-28-2022

Hi!

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


RE: Controller & Model Name - InstantT - 06-28-2022

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)