Question
I would like to setup some little ajax support for my joomla page, in detail: I would like to send logging messages from the frontend to the backend via ajax and store them in database.
In drupal this can be done by adding a path and a callback inside a module, so how can this be achieved in joomla 2.5, so that there is an url like:
http://www.domain.com/log
which leads to a function call?
Greetings..
Solution
The proper way would be to create a component to handle the call, but as you write most of the time it seems a bit overkill for just a module. Another way would be to create a standalone php-file that uses the Joomla-library. This file could then easily be called from wherever you like. It's like a mini-version of Joomla with the advantage of having all libraries available:
define( 'DS', DIRECTORY_SEPARATOR );
if (!defined('JPATH_BASE')){
define('JPATH_BASE', '..'.DS.'..'.DS.'..');
}
define('JPATH_LIBRARIES', JPATH_BASE . DS . 'libraries');
require_once JPATH_LIBRARIES . DS . 'import.php';
$var = JRequest::getVar('my_var');
To access the DB-object, you would need to manually set the options to the DB-object since this file won't access the configuration files (you can program this of course).
$option = array(); //prevent problems
$option['driver'] = 'mysql'; // Database driver name
$option['host'] = 'db.myhost.com'; // Database host name
$option['user'] = 'myuser'; // User for database authentication
$option['password'] = 'mypass'; // Password for database authentication
$option['database'] = 'bigdatabase'; // Database name
$option['prefix'] = 'abc_'; // Database prefix (may be empty)
$db = & JDatabase::getInstance( $option );