How to run joomla component functions from console

by user4035   Last Updated February 10, 2018 22:10 PM

I am developing a component and want to create a test file that will load necessary Joomla libraries and then run a function from my class in console.

Component directory looks like this:

/com_auditingchecks
  /controllers
  /helpers
  /models
  /views
  auditingchecks.php
  controller.php
  test.php

I want to run:

$php test.php

and it will automatically run necessary functions that I develop. So far I created this:

<?php

/**
 * Constant that is checked in included files to prevent direct access.
 * define() is used in the installation folder rather than "const" to not error for PHP 5.2 and lower
 */
define('_JEXEC', 1);
$dir = __DIR__;
$dir = preg_replace('/components.*/', "", $dir);

if (file_exists($dir . '/defines.php'))
{
    include_once $dir . '/defines.php';
}

if (!defined('_JDEFINES'))
{
    define('JPATH_BASE', $dir);
    require_once JPATH_BASE . '/includes/defines.php';
}

require_once JPATH_BASE . '/includes/framework.php';
$app = JFactory::getApplication('site');

//What next? How to load base joomla libraries and then a class from my component?

//This loads the class, but unfortunately JPATH_COMPONENT is undefined
JLoader::register('AuditingChecksModelFiles', JPATH_COMPONENT. DIRECTORY_SEPARATOR .'models' . DIRECTORY_SEPARATOR . 'files.php');


Related Questions


Using CodeMirror editor in custom component

Updated October 09, 2016 09:04 AM


Call Controller's Publish-Method from CLI or Helper

Updated March 02, 2016 01:04 AM

Using external library with a component

Updated February 03, 2018 20:10 PM