1

What drives me crazy with Joomla! and I still don't understand: If I create a model for a component or module and this consists of several words (for example File Item) then I call the model in CamelCase: "FileItemModel" and the file "FileItemModel.php". The same applies to helpers or controllers. The whole thing works wonderfully on the localhost (where case sensitive plays no role) but as soon as I load the whole thing onto a server (unix aka case sensitive) it no longer works. The server is like this: "naaah i cannot see this file / class anywhere must be your fault".

Does Joomla! forbid me to use CamelCase if a class / model / controller / helper / field consists of several "naming parts"? Am I doing something wrong? Do I need to set a "Magic Trigger" somewhere? :-) If so, I would like to know how I can do it better / what I have to pay attention to.

As I said, this has become a habit for me and I write my classes permanently in the CamelCase aka wrong format while coding and then forget it again and have to rewrite every affected class. Apart from that, I don't find it particularly legible when it's "partly" CamelCase...

Edit: Joomla! uses this CamelCase pattern with multiple words too for example: BaseDatabaseModel

Edit 2: OK for "fields" like the "BackendHelperField" you need to specify the $type like this:

class BackendHelperField extends FormField { protected $type = 'backendHelper'; ... } 

and call it loke this:

<field name="backend-helper" type="backendHelper" /> 

so you need to adapt the camelCase into the type when calling the file BackendHelperField.php and the class BackendHelperField.

But what I don't understand is for example the main helper for a module. If the module is called "Nice Extension" the "main" helper file should be named "NiceExtensionHelper" in the file "NiceExtensionHelper.php" but this does not work the helper needs to be renamed to "NiceextensionHelper" and the file also to "NiceextensionHelper.php" with the namespace: NiceCompany\Module\NiceExtension where the Helper is in namespace NiceCompany\Module\NiceExtension\Site\Helper. But when doing for example an AJAX Call to the Helper it want find the file if the Helper class is correctly named in CamelCase "NiceExtensionHelper" in "NiceExtensionHelper.php" you need to name it wrong (NiceextensionHelper) so that com_ajax will find it. Is this a bug?

Same happens for component models and controllers I was never able to use "multi word CamelCase" models or controllers when they got tested on a server and not localhost.

Any hint / information would be usefull - afaik the manuals does not explain this issue / topic.

Edit 3 for Sharky: For the Module example, there is a Custom Field with a Button that sends an AJAX POST to the Helper:

... $.ajax({ url: '/index.php?option=com_ajax&module=niceextension&method=addFolderRestriction&data='+data+'&format=json', type: "post", success :function(response){ // Change status icon and manage buttons if(response.data.success){...} ... 

And then in mod_niceextension/src/helper/NiceExtensionHelper.php

... class NiceExtensionHelper { ... public static function addFolderRestrictionAjax(){ ... $input = Factory::getApplication()->input; $dataStr = $input->get('data', '{}', 'RAW'); $data = json_decode($dataStr); ... } } 

*Sidenote: I know I'm currently using post but the data got transmitted in the url AND I need to update the AJAX Code to get rid of jQuery > I'm refactoring the module currently. And I am aware of that. But the main issue is that the class will not be found on the server when using this CamelCase Syntax.

The slash in front of the url is because it will be called from the module backend settings not from within the frontend.*

When I rename the Helper file and the classname (to NiceextensionHelper) it works. (Joomla! 5.2.x and PHP 8.3.x)

I could create a small github repo with an example module that shows what I mean.

Update: I've created an example repo with two branches GitHub

  • main branch: Main Module Helper with CamelCase works on localhost but not on server (NiceExtensionHelper) I think because of case sensibility.
  • working-on-servers-with-case-sensitivity branch: Removed CamelCase naming for Main Helper (NiceextensionHelper)
3
  • 1
    "but this does not work the helper needs to be renamed to "NiceextensionHelper"" - Can you clarify how and where you're calling the module helper? Commented Mar 6 at 17:38
  • Sure I've added more info - I could also create a small demo repo (module) if needed? Commented Mar 6 at 18:04
  • I've created a small Example here: github.com/marcorensch/CaseSensitivityExample. you can check the branches to see the difference Commented Mar 6 at 19:31

1 Answer 1

1

My first advice would be to rename the extension itself, if that's possible. I don't know if it's documented anywhere, but if you look at core modules, you can see they separate words using underscores. E.g. it's mod_articles_category, not mod_articlescategory. If you renamed your module to mod_nice_extension, also changing the module parameter in com_ajax to nice_extension, that should work flawlessly.

If renaming is not possible, another option is to create your own implementation of Joomla\CMS\Helper\HelperFactoryInterface or extend the default Joomla\CMS\Helper\HelperFactory class to manually transform the name argument:

public function getHelper(string $name, array $config = []) { if ($name === 'NiceextensionHelper') { $name = 'NiceExtensionHelper'; } return parent::getHelper($name, $config); } 

There's also an option of changing the capitalization of the module parameter to niceExtension. But while it may seem simple and obvious, it could still have case sensitivity issues but this time in the database, i.e. when using PostgreSQL. This is because the parameter is also used to load the module record from the database.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.