Naming convention for package controllers

Permalink
I always use StudlyCaps for my classes and namespace (https://www.php-fig.org/psr/psr-1/#3-namespace-and-class-names). I am new to concrete5 and am creating a package. It works great when the controller class names are under-case, but the second one starts with a capital letter, I get a class not found error. I've looked at vendor/composer's autoloader and it doesn't appear to be modified to only allow lowercase. Does concrete5 override it?. Don't know if relevant but concrete5 was installed using composer (https://github.com/concrete5/composer). Thanks

EDIT. It appears that most of the time, the class name can start with a capital letter but just not the filename. And while the class name may start with a capital, it cannot contain another capital letter. But, I see examples in the docs where they use SamplePackage, so I don't know what is going on.

 
mnakalay replied on at Permalink Reply
mnakalay
Hello
If you're talking about the package's controller than the filename must be controller all lower case and its class name must be Controller.

What's important is the naming of the package's folder itself. It must be all lower case with underscores instead of spaces. Then you use the camel case version of the folder name in your namespacing.

So say your package's folder is my_new_package then your controller's namespace will be Concrete\Package\MyNewPackage.

So you have packages/my_new_package/controller.php with namespace
namespace Concrete\Package\MyNewPackage;

And class
class Controller extends Package
NotionCommotion replied on at Permalink Reply
Hi mnakalay,

No, not that controller but this controller =>https://documentation.concrete5.org/developers/working-with-pages/si... I think the following from this section of the docs might be related, but not positive and it doesn't address all underscore file naming.

The name space of any single page controller in the root application/ directory begins with Application\Controller\SinglePage and then continues with the camel-cased URL segments down to its page name. The class is named the same as the last portion of the segment (but camelcased, with the first segment also capitalized) and it needs to extend the Concrete\Core\Page\Controller\PageController class.
mnakalay replied on at Permalink Best Answer Reply
mnakalay
I see.

For single pages you have different ways of doing it.

So say your page's filename is my_single_page

So the view will be
application/single_pages/my_single_page.php

And the controller will be in
application/controllers/single_page/my_single_page.php

Notice that for the controller, it's single_page with no "s" but for the view, it's single_pages with an "s"

For the controller, namespace will be
Application\Controller\SinglePage


You'll notice that although the folder is controllers with an "s", in the namespace the "s" disappears.

and the class name
class MySinglePage extends PageController

In a package, the path for the files will be the same except inside packages/your_package_folder instead of application so for the view
packages/my_package/single_pages/my_single_page.php
and for the controller
packages/my_package/controllers/single_page/my_single_page.php

So the controller's namespace will change to
Concrete\Package\MyPackage\Controller\SinglePage


Is that what you were looking for?
NotionCommotion replied on at Permalink Reply
Yes mnakalay, that was exactly what I was looking for. Thanks!

Took me a couple times to read through it. Yeah, I read about making sure I get the "s" part right. So, files are always lower case snake case, right? Is this a more wide range Concrete5 standard and not just single pages?
mnakalay replied on at Permalink Reply
mnakalay
most of the time yes files are snake cased. EXCEPT for anything you put in the package's src folder. In that case, it's all camel-cased.