Jaxel
Well-known member
So one of my data types in my Rio addon is called "service". I am trying to export a service's data to XML. I'm trying to do this through the XF Service system... but I'm having a bug that I can't figure out. I think I may be getting lost somewhere because of the inherent confusion of exporting a data type called "service", through a system called "service".
My controller action:
And this is my service:
When I execute the action however, I get the following error:
My controller action:
Code:
public function actionExport(ParameterBag $params)
{
$service = $this->assertServiceExists($params->service_id);
$this->setResponseType('xml');
$exporter = $this->service('EWR\Rio:ServiceExport', $service);
$viewParams = [
'xml' => $exporter->exportToXml(),
'filename' => $exporter->getExportFileName()
];
return $this->view('EWR\Rio:ServiceExport', '', $viewParams);
}
And this is my service:
Code:
namespace EWR\Rio\Service\ServiceExport;
use EWR\Rio\Entity\Service;
class ServiceExport extends \XF\Service\AbstractService
{
protected $service;
public function __construct(Service $service)
{
parent::__construct($app);
$this->setService($service);
}
public function setService(Service $service)
{
$this->service = $service;
}
public function getExportFileName()
{
$title = str_replace(' ', '-', utf8_romanize(utf8_deaccent($this->service->service_name)));
return "{$title}.xml";
}
public function exportToXml()
{
$document = new \DOMDocument('1.0', 'utf-8');
$document->formatOutput = true;
$topNode = $document->createElement('service');
$topNode->appendChild($document->createElement('name', $service->service_name));
$topNode->appendChild($document->createElement('bbcode', $service->service_bbcode));
$topNode->appendChild($document->createElement('callback', $service->service_callback));
$document->appendChild($topNode);
return $document;
}
}
When I execute the action however, I get the following error:
LogicException: Class EWR\Rio\Service\ServiceExport does not exist in src/XF/Container.php at line 267
- XF\Container->createObject() in src/XF/App.php at line 1318
- XF\App->XF\{closure}() in src/XF/Container.php at line 228
- XF\Container->create() in src/XF/App.php at line 2456
- XF\App->service()
- call_user_func_array() in src/XF/Mvc/Controller.php at line 699
- XF\Mvc\Controller->service() in src/addons/EWR/Rio/Admin/Controller/Service.php at line 67
- EWR\Rio\Admin\Controller\Service->actionExport() in src/XF/Mvc/Dispatcher.php at line 249
- XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 89
- XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 41
- XF\Mvc\Dispatcher->run() in src/XF/App.php at line 1879
- XF\App->run() in src/XF.php at line 328
- XF::runApp() in admin.php at line 13