XF 2.0 Exporting through a service, an entity called "service"... lol

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:
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

  1. XF\Container->createObject() in src/XF/App.php at line 1318
  2. XF\App->XF\{closure}() in src/XF/Container.php at line 228
  3. XF\Container->create() in src/XF/App.php at line 2456
  4. XF\App->service()
  5. call_user_func_array() in src/XF/Mvc/Controller.php at line 699
  6. XF\Mvc\Controller->service() in src/addons/EWR/Rio/Admin/Controller/Service.php at line 67
  7. EWR\Rio\Admin\Controller\Service->actionExport() in src/XF/Mvc/Dispatcher.php at line 249
  8. XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 89
  9. XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 41
  10. XF\Mvc\Dispatcher->run() in src/XF/App.php at line 1879
  11. XF\App->run() in src/XF.php at line 328
  12. XF::runApp() in admin.php at line 13
 
The word "Service" appears so many times in your post the word has lost all meaning :P

The problem is the namespace most likely. Try this: namespace EWR\Rio\Service;


Fillip
 
Doh... I'm so stupid. Yeah. The amount of times "Service" appears was wracking my brain.
 
Check your constructor in the service as well, it seems to be missing the default parameters :)

Liam
 
Back
Top Bottom