Chyba 500 Jhtml in Joomla4.X Topic is solved

For Joomla! 4.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
Studio555
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Wed Nov 15, 2023 10:34 am

Chyba 500 Jhtml in Joomla4.X

Post by Studio555 » Thu Apr 18, 2024 1:21 pm

I am converting a component from J3.X to J4 and I have an unsolved problem for me. To display the date selection, the J3.X version displayed the code:

Code: Select all

  <?php if ($listek == 'denni'): ?>  
            <form action=""  class="hidden-print" name="dateRange" method="post">
            
            <?php echo JHtml::_('jidelnilistek.listmenus', $menuTypeId, 'menuId', $addItems ? $addItems->id : '', $js); ?>
                          
            </form>
            <?php endif;?>
This code used the file "Helpers/html/jidelnilistek.php" where the class "class jidelnilistek" and "public static function listmenus" were declared.

In version J4 this is not possible - error message: "500 JHtml jidelnilistek not found". I know that this part of the code will need to be refactored into HTMLHelpers, but I'm not entirely sure how. Any advice or help out there?

thank you for any advice
Milan

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2930
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Chyba 500 Jhtml in Joomla4.X

Post by SharkyKZ » Thu Apr 18, 2024 1:48 pm

This should still be working in J5. You could file a bug report but don't hold your breath. The way going forward is to register the class with the service registry:

Code: Select all

use Joomla\CMS\HTML\HTMLHelper;

HTMLHelper::getServiceRegistry()->register('jidelnilistek', new YourServiceClass);
If the class is static, you can register it by name:

Code: Select all

HTMLHelper::getServiceRegistry()->register('jidelnilistek', YourServiceClass::class);

Studio555
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Wed Nov 15, 2023 10:34 am

Re: Chyba 500 Jhtml in Joomla4.X

Post by Studio555 » Thu Apr 18, 2024 5:22 pm

Thank you for answer.
I used this in "default.php" file

Code: Select all

HTMLHelper::getServiceRegistry()->register('jidelnilistek', new jidelnilistek);
As a result, it still doesn't find the class:
Class "jidelnilistek" not found

I assume that the file with the new class "jidelnilistek.php" will be in the directory "Helpers"

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2930
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Chyba 500 Jhtml in Joomla4.X

Post by SharkyKZ » Thu Apr 18, 2024 5:54 pm

You have to load the class yourself. Modern J4+ components use namespaced classes with PSR-4 autoloading. If you haven't converted to this yet, you can use the old JLoader::register() method.

Studio555
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Wed Nov 15, 2023 10:34 am

Re: Chyba 500 Jhtml in Joomla4.X

Post by Studio555 » Thu May 02, 2024 9:55 am

Thank you very much for your help. It's OK.


Post Reply

Return to “Joomla! 4.x Coding”