#1841 – Load class TaxiBookingControllerRoutes

Posted in ‘Taxi Booking for Joomla’
This is a public ticket. Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.
Wednesday, 28 August 2019 20:56 BST
serguei_kp
SystemPay for Taxi Booking, Taxi Booking recurring updates Annually
Hello team!
I'm working on the script that will synchronize the special routes between my database and Taxibooking.

I'm trying to call a method "save" from the class TaxiBookingControllerRoutes, but I've got an error : Server raised fault: 'Class 'TaxiBookingController' not found'
Can you help me to call the method from inside other component?
I need to save special route data into the database.

This is the script in my component :
if (!class_exists('TaxiBookingControllerRoutes'))
require JPATH_BASE.DS.'components'.DS.'com_taxibooking'.DS.'controllers'.DS.'routes.php';

$TaxiBookingControllerRoutes = new TaxiBookingControllerRoutes;
$response=$TaxiBookingControllerRoutes->save($product);

Best regards.
 
Thursday, 29 August 2019 07:43 BST
ronniee
RedSys for Taxi Booking
Hi Serge,

I think you should use models instead of controller to save data into Joomla database from external source. Below is sample code snippet which you should use

//load model
JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_taxibooking' . DIRECTORY_SEPARATOR . 'models');

//get instance of model class, where class name will be TaxibookingModelRoute
$model = JModelLegacy::getInstance('Route', 'TaxibookingModel');

//call model method
$baz = $model->save($product);


Before this you have to load Joomla core application in your external script. The following should work

define('_JEXEC', 1);    

// this file is in a subfolder 'scripts' under the main joomla folder
define('JPATH_BASE', realpath(dirname(__FILE__) . '/..'));
require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_BASE . '/includes/framework.php';

// instantiate application
$app   = JFactory::getApplication('site');


Hope this helps
Ronniee
 
Thursday, 29 August 2019 15:26 BST
serguei_kp
SystemPay for Taxi Booking, Taxi Booking recurring updates Annually
Hi Ronniee, thank you!
I can call methods from model.

Now I run in the error like this:
Error in creating Product(s).Server raised fault: 'Call to a member function getKeyName() on bool'

If I call directly "save" method inside this method is another one "if (parent::save($post))"
which calls parent class's "save" method, but the variable $table is false, while usually it mast be $table TaxibookingTableRoute.

May be "save" method needs more parameters, but how to provide them? When I add a route from the Taxibooking backend, the controller provides all requested parameters to the model, but if I call the model directly I have to find a way to provide all requested parameters. That is why I looked for the way to access to controller methods but I didn't find how.

This is my code:
//load model
JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_taxibooking' . DS . 'models');
//get instance of model class, where class name will be TaxibookingModelRoute
$model = JModelLegacy::getInstance('Route', 'TaxibookingModel');
//call model method

$response = $model->save($product);

Best regards.
 
Thursday, 29 August 2019 17:07 BST
serguei_kp
SystemPay for Taxi Booking, Taxi Booking recurring updates Annually
Hi Ronniee, I found a solution:
// Set the table directory
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_taxibooking'.DS.'tables');

Now I can add the route.
Thank you!
 
This ticket is closed, therefore read-only. You can no longer reply to it. If you need to provide more information, please open a new ticket and mention this ticket's number.

KANEV Web Development limited is not affiliated with or endorsed by the Joomla Project or Open Source Matters.

KANEV Web Development limited is registered in England and Wales #8902407