PHP [SOLVED]: PHP 's' in namespace: Controller or Controllers, Model or Models?

PHP [SOLVED]: PHP 's' in namespace: Controller or Controllers, Model or Models?

Home Forums Scripting PHP Tutorials PHP [SOLVED]: PHP 's' in namespace: Controller or Controllers, Model or Models?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #245530

    Cloudy Point
    Keymaster

    QuestionQuestion

    For example Symfony uses Controller. Yii2 uses controllers and models.

    Is there a standard about ...s|es like PSR?

    #245531

    Cloudy Point
    Keymaster

    Accepted AnswerAnswer

    None of the PSRs specify whether to use singular or plural in namespaces. This is usually a convention by the framework. The same goes for capitalization.

    Whether you can use your preferred naming convention – if you have any – in the framework of your choosing mostly depends on the framework itself and might even vary within parts of the framework. In the case of Symfony it is singular AppController by default, but it’s easily changed to AppControllers or Appcontrollers if you like as long as your routing configuration uses the correct name.

    When deviating from the framework’s convention you might run into problems, because of the expectations it has when configuring your app. For example Symfony 3 autoloads your Commands when they are placed in the Command/ folder and the class name is suffixed with Command. When you deviate from this you have to manually register them. On the other hand Symfony 4 uses the new autiwiring and autoconfigure defaults in the service configuration and will detect commands based on whether they implement the correct interface – either directly or indirectly by extending the base Command-class – and therefore can have whatever name you like and can be put in any folder. So even within the framework or between different versions of the framework changing the name to something other than the recommendation might have different repercussions.

    Source: https://stackoverflow.com/questions/48020536/php-s-in-namespace-controller-or-controllers-model-or-models
    Author: dbrumann
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.