Advertisement

how com-ajax define the module's helper file ? Topic is solved

For Joomla! 5.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
yana22
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri Feb 07, 2025 6:00 am

how com-ajax define the module's helper file ?

Post by yana22 » Fri Feb 07, 2025 6:13 am

joomla 5.2.3 .
component = com-ajax .
in file ajax.php i see this 2 codes :

Code: Select all

 $helperFile = JPATH_BASE . '/modules/mod_' . $module . '/helper.php';
 
 and :
 
 elseif ($results === null) {
            // The helper file does not exist
            $results = new RuntimeException(Text::sprintf('COM_AJAX_FILE_NOT_EXISTS', 'mod_' . $module . '/helper.php'), 404);
        }
 
com-ajax try to find helper.php in the root of the module folder .
but in the mod_hello tutorial https://manual.joomla.org/docs/building ... tep9-ajax/
there is no helper.php in the root of the module folder .
but there is mod_hello/src/Helper/HelloHelper.php

how com-ajax defined the HelloHelper.php and not send error helper.php COM_AJAX_FILE_NOT_EXISTS

how it works ? what is the secret ?

Advertisement
User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 31660
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: how com-ajax define the module's helper file ?

Post by Per Yngve Berg » Fri Feb 07, 2025 6:29 am

Mod. Note: Relocated topic from Beginner to the Coding Forum.

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

Re: how com-ajax define the module's helper file ?

Post by SharkyKZ » Fri Feb 07, 2025 6:40 am

Modern modules should implement Joomla\CMS\Helper\HelperFactoryInterface. Core modules use Joomla\CMS\Helper\HelperFactory implementation.

yana22
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri Feb 07, 2025 6:00 am

Re: how com-ajax define the module's helper file ?

Post by yana22 » Fri Feb 07, 2025 8:27 am

SharkyKZ wrote: Fri Feb 07, 2025 6:40 am Modern modules should implement Joomla\CMS\Helper\HelperFactoryInterface. Core modules use Joomla\CMS\Helper\HelperFactory implementation.
i added this code in my dispatcher file and still get error helper.php not exists :

use Joomla\CMS\Helper\HelperFactoryInterface;

??

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

Re: how com-ajax define the module's helper file ?

Post by SharkyKZ » Fri Feb 07, 2025 8:49 am

If you're following the tutorial and something doesn't work, you can download the files from here and work with them https://github.com/joomla/manual-exampl ... e-tutorial.

tolkachyov_s
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Fri Aug 26, 2022 1:34 pm

Re: how com-ajax define the module's helper file ?

Post by tolkachyov_s » Fri Feb 07, 2025 10:31 am

You file structure should be like:

Code: Select all

Yourmodulename.xml
- services
- - provider.php
- src
- - Dispatcher
- - - Dispatcher.php
- - Helper
- - - YourmodulenameHelper.php
- tmpl
- - default.php
All files names and classes names, namespaces are case sensitivity. You can try to reinstall module.
Then in services/provider.php add your module helper:

Code: Select all

<?php
/**
 * @package     WT Yandex Map items
 *
 * @copyright   (C) 2022 Sergey Tolkachyov
 * @link https://web-tolk.ru
 * @license     GNU General Public License version 2 or later
 */

defined('_JEXEC') or die;

use Joomla\CMS\Extension\Service\Provider\HelperFactory;
use Joomla\CMS\Extension\Service\Provider\Module;
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;

/**
 * The WT Yandex map items module service provider.
 *
 * @since  1.0.0
 */
return new class implements ServiceProviderInterface
{
	/**
	 * Registers the service provider with a DI container.
	 *
	 * @param   Container  $container  The DI container.
	 *
	 * @return  void
	 *
	 * @since   4.0.0
	 */
	public function register(Container $container)
	{   
        // Module namespace 
		$container->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\Wtyandexmapitems'));
        // Module HELPER Namespace 
		$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\Wtyandexmapitems\\Site\\Helper'));
		$container->registerServiceProvider(new Module);
	}
};

yana22
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri Feb 07, 2025 6:00 am

Re: how com-ajax define the module's helper file ?

Post by yana22 » Fri Feb 07, 2025 2:36 pm

tolkachyov_s wrote: Fri Feb 07, 2025 10:31 am You file structure should be like:

Code: Select all

Yourmodulename.xml
- services
- - provider.php
- src
- - Dispatcher
- - - Dispatcher.php
- - Helper
- - - YourmodulenameHelper.php
- tmpl
- - default.php
All files names and classes names, namespaces are case sensitivity. You can try to reinstall module.
Then in services/provider.php add your module helper:

Code: Select all

<?php
/**
 * @package     WT Yandex Map items
 *
 * @copyright   (C) 2022 Sergey Tolkachyov
 * @link https://web-tolk.ru
 * @license     GNU General Public License version 2 or later
 */

defined('_JEXEC') or die;

use Joomla\CMS\Extension\Service\Provider\HelperFactory;
use Joomla\CMS\Extension\Service\Provider\Module;
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;

/**
 * The WT Yandex map items module service provider.
 *
 * @since  1.0.0
 */
return new class implements ServiceProviderInterface
{
	/**
	 * Registers the service provider with a DI container.
	 *
	 * @param   Container  $container  The DI container.
	 *
	 * @return  void
	 *
	 * @since   4.0.0
	 */
	public function register(Container $container)
	{   
        // Module namespace 
		$container->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\Wtyandexmapitems'));
        // Module HELPER Namespace 
		$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\Wtyandexmapitems\\Site\\Helper'));
		$container->registerServiceProvider(new Module);
	}
};
yes i have all these files and i added your code but still has same issue :
helper.php not exists

yana22
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri Feb 07, 2025 6:00 am

Re: how com-ajax define the module's helper file ?

Post by yana22 » Sat Feb 08, 2025 8:17 pm

this is the full code of all my module files :
please help me to get where is my fault ?

the xml file : mod_yendifvideoshare_videos.xml

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="4.0" method="upgrade" client="site">
    <name>mod_yendifvideoshare_videos</name>
    <creationDate>January 2025</creationDate>
    <copyright>Copyright (c) 2012 - 2025 PluginsWare Interactive Pvt. Ltd. All Rights Reserved.</copyright>
    <license>GNU General Public License version 2 or later; see LICENSE.txt</license>
    <author>PluginsWare Interactive Pvt. Ltd</author>
    <authorEmail>[email protected]</authorEmail>
    <authorUrl>https://yendifplayer.com/</authorUrl>
    <version>2.1.4</version>
    <description>MOD_YENDIFVIDEOSHARE_VIDEOS_XML_DESCRIPTION</description>
    <namespace path="src">PluginsWare\Module\YendifVideoShareVideos</namespace>  
	
	
    <files>
		<folder module="mod_yendifvideoshare_videos">services</folder>
		<folder>src</folder>
        <folder>tmpl</folder>
	    <folder>language</folder>
    </files>
	
	 <scriptfile>script.php</scriptfile>
    <media destination="mod_yendifvideoshare_videos" folder="media">
        <filename>joomla.asset.json</filename>
        <folder>js</folder>
    </media>
	
	
    <config>
        <fields name="params"> ....
this is my helper code : YendifVideoShareVideosHelper.php

Code: Select all

<?php
/**
* @version     2.1.1
* @package     Com_YendifVideoShare
* @subpackage  Mod_YendifVideoShare_Videos
* @author      PluginsWare Interactive Pvt. Ltd <[email protected]>
* @copyright   Copyright (c) 2012 - 2023 PluginsWare Interactive Pvt. Ltd. All Rights Reserved.
* @license     GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace PluginsWare\Module\YendifVideoShareVideos\Site\Helper;

\defined( '_JEXEC' ) or die;

use Joomla\CMS\Factory;
use Joomla\Registry\Registry;
use Joomla\Database\DatabaseInterface;
use Joomla\Module\Logged\Administrator\Helper\LoggedHelper;
use Joomla\CMS\Language\Text;

/**
* Helper for mod_yendifvideoshare_videos
*
* @since  2.0.0
*/
Class YendifVideoShareVideosHelper {

/**
* Retrieve videos
*
* @param   Joomla\Registry\Registry  &$params  Module parameters
*
* @return  array  The videos list.
* 
* @since   2.0.0
*/
public static function getItemsAjax( &$params ) {
$app = Factory::getApplication();	
$db = Factory::getDbo();			

$query = 'SELECT * FROM #__yendifvideoshare_videos WHERE state = 1';

if ( $catid = $params->get( 'catid' ) ) {
if ( is_array( $catid ) ) {
$catids = array_map( 'intval', $catid );
$catids = array_filter( $catids );

if ( ! empty( $catids ) ) {
$query .= ' AND catid IN (' . implode( ',', $catids ) . ')';
}
} else {
$query .= ' AND catid = ' . (int) $catid;
}
}

if ( $app->input->get( 'option' ) == 'com_yendifvideoshare' && $app->input->get( 'view' ) == 'video' && $id = $app->input->getInt( 'id' ) ) {
$query .= ' AND id != ' . $id;
}

if ( $params->get( 'filterby' ) == 'featured' ) {
$query .= ' AND featured = 1';
}

if ( $params->get( 'schedule_video_publishing' ) ) {			
$nullDate = $db->getNullDate();
$nowDate  = Factory::getDate()->toSql();

$query .= ' AND (published_up IS NULL OR published_up = ' . $db->quote( $nullDate ) . ' OR published_up <= ' . $db->quote( $nowDate ) . ')';
$query .= ' AND (published_down IS NULL OR published_down = ' . $db->quote( $nullDate ) . ' OR published_down >= ' . $db->quote( $nowDate ) . ')';
}	

switch ( $params->get( 'orderby' ) ) {
case 'latest':
$query .= ' ORDER BY id DESC';
break;
case 'date_added':
$query .= ' ORDER BY created_date DESC';
break;
case 'most_viewed':
$query .= ' ORDER BY views DESC';
break;
case 'most_rated':
$query .= ' ORDER BY rating DESC';
break;
case 'a_z':
$query .= ' ORDER BY title ASC';
break;
case 'z_a':
$query .= ' ORDER BY title DESC';
break;
case 'random':
$query .= ' ORDER BY RAND()';
break;
default:
$query .= ' ORDER BY ordering ASC';
}			

$limit = (int) $params->get( 'no_of_rows', 3 ) * (int) $params->get( 'no_of_cols', 3 );

$db->setQuery( $query, 0, $limit );
$items = $db->loadObjectList();

return $items;		
}
}

this is my dispatcher code dispatcher.php

Code: Select all

<?php

namespace PluginsWare\Module\YendifVideoShareVideos\Site\Dispatcher;

\defined('_JEXEC') or die;

use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
use Joomla\CMS\Helper\HelperFactoryAwareInterface;
use Joomla\CMS\Helper\HelperFactoryInterface;
use Joomla\CMS\Helper\HelperFactoryAwareTrait;
use Joomla\CMS\Language\Text;
use PluginsWare\Module\YendifVideoShareVideos\Site\Helper\YendifVideoShareVideosHelper;

class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
{
    use HelperFactoryAwareTrait;

}
this is my provider.php code

Code: Select all

<?php
/**
 * @package     WT Yandex Map items
 *
 * @copyright   (C) 2022 Sergey Tolkachyov
 * @link https://web-tolk.ru
 * @license     GNU General Public License version 2 or later
 */

defined('_JEXEC') or die;

use Joomla\CMS\Extension\Service\Provider\HelperFactory;
use Joomla\CMS\Extension\Service\Provider\Module;
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;

/**
 * The WT Yandex map items module service provider.
 *
 * @since  1.0.0
 */
return new class implements ServiceProviderInterface
{
	public function register(Container $container)
	{   
        // Module namespace 
		$container->registerServiceProvider(new ModuleDispatcherFactory('\\PluginsWare\\Module\\YendifVideoShareVideos'));
        // Module HELPER Namespace 
		$container->registerServiceProvider(new HelperFactory('\\PluginsWare\\Module\\YendifVideoShareVideos\\Site\\Helper'));
		$container->registerServiceProvider(new Module);
	}
};
this is my joomla.asset json code :

Code: Select all

{
  "$schema": "https://developer.joomla.org/schemas/json-schema/web_assets.json",
  "name": "mod_yendifvideoshare_videos",
  "version": "1.0.0",
  "description": "videos module to show videos on the site",
  "license": "GPL-2.0-or-later",
  "assets": [
    {
      "name": "mod_yendifvideoshare_videos.add-suffix",
      "type": "script",
      "uri": "mod_yendifvideoshare_videos/add-suffix.js",
      "dependencies": [
        "jquery", "core", "messages"
      ],
      "version": "1.1.0"
    } 
  ]
}
this is my js code add-suffix.js :

Code: Select all

function loadmore_videos() {
    let loadvideos = document.querySelector('.sof-videos-row');
    Joomla.request({
        url: 'index.php?option=com_ajax&module=yendifvideoshare_videos&method=getItems&format=json',
        method: 'POST',
        onSuccess(data) {
            const response = JSON.parse(data);
            if (response.success) {
                loadvideos.innerHTML = response.data;
            } else {
                const messages = {"error": [response.message]};
                Joomla.renderMessages(messages);
            }
        },
        onError(xhr) {
            Joomla.renderMessages(Joomla.ajaxErrorsMessages(xhr));
            const response = JSON.parse(xhr.response);
            Joomla.renderMessages({"error": [response.message]}, undefined, true);
        }
    });
}
this is my code in default.php (not all the file code):

Code: Select all

<?php

defined( '_JEXEC' ) or die;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Date\Date;
use Joomla\CMS\Factory;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Uri\Uri;
use PluginsWare\Component\YendifVideoShare\Site\Helper\YendifVideoShareHelper;
use PluginsWare\Component\YendifVideoShare\Site\Helper\YendifVideoSharePlayer;
use PluginsWare\Component\YendifVideoShare\Site\Helper\YendifVideoShareRoute;
use PluginsWare\Module\YendifVideoShareVideos\Site\Helper\YendifVideoShareVideosHelper;

$document = $app->getDocument();
$wa = $document->getWebAssetManager();
$wr = $wa->getRegistry();
$wr->addRegistryFile('media/mod_yendifvideoshare_videos/joomla.asset.json');
$wa->useScript('mod_yendifvideoshare_videos.add-suffix');

// Pass the suffix to add down to js
$document->addScriptOptions('vars', array('suffix' => "!"));

$app = Factory::getApplication();

<div class="yendif-row sof-videos-row"></div>

<div onClick="loadmore_videos()" class="sof-loadmore-button" >see more videos</div>
my issue is :

Code: Select all

The file at mod_yendifvideoshare_videos/helper.php does not exist.
how to address the com-ajax to define the function getItemsAjax in YendifVideoShareVideosHelper.php ?

i hope some one can help me to fix my issue

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

Re: how com-ajax define the module's helper file ?

Post by SharkyKZ » Sat Feb 08, 2025 9:02 pm

It could be a capitalization issue. With current AJAX URL the class name should be YendifvideoshareVideosHelper. Or you can change the URL to keep using YendifVideoShareVideosHelper:

Code: Select all

index.php?option=com_ajax&module=YendifVideoShare_videos&method=getItems&format=json

yana22
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri Feb 07, 2025 6:00 am

Re: how com-ajax define the module's helper file ?

Post by yana22 » Sat Feb 08, 2025 10:36 pm

SharkyKZ wrote: Sat Feb 08, 2025 9:02 pm It could be a capitalization issue. With current AJAX URL the class name should be YendifvideoshareVideosHelper. Or you can change the URL to keep using YendifVideoShareVideosHelper:

Code: Select all

index.php?option=com_ajax&module=YendifVideoShare_videos&method=getItems&format=json
i tried your advice , but still have same issue .

tolkachyov_s
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Fri Aug 26, 2022 1:34 pm

Re: how com-ajax define the module's helper file ?

Post by tolkachyov_s » Thu Feb 13, 2025 10:13 am

Try to reinstall your module: remove and install. And true, it is a capitalization issue.

yana22
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri Feb 07, 2025 6:00 am

Re: how com-ajax define the module's helper file ?

Post by yana22 » Mon Feb 17, 2025 5:34 pm

tolkachyov_s wrote: Thu Feb 13, 2025 10:13 am Try to reinstall your module: remove and install. And true, it is a capitalization issue.
solved

thanks

Advertisement

Post Reply

Return to “Joomla! 5.x Coding”