This is getting me crazy. I know the answer will be stupid but around 1 and half day on this I need to ask, English isn't my native language so be patient please. First of all I'm trying to write a simple service but continuously getting the error
The autoloader expected class "AppBundle\Services\Helpers" to be defined in file "C:\xampp7.1.7\htdocs\curso-fullstack\vendor\composer/../../src/AppBundle\Services\Helpers.php". The file was found but the class was not in it, the class name or namespace probably has a typo.
on my services.yml file I got this
app.helpers:
class: AppBundle\Services\Helpers
arguments:
- ["null"]
to define the service
my folder structure is src/AppBundle/Services/Helpers.php where I got the service class as follow
<?php
namespace AppBundle\Services\Helpers;
class Helpers {
/* Funcion encargada de devolvernos un objeto json */
public function jsonTemplate( $data ) {
$normalizers = array( new GetSetMethodNormalizer() );
$encoders = array( "json" => new JsonEncoder() );
$serializer = new Serializer( $normalizers, $encoders );
$json = $serializer->serialize( $data, 'json' );
$response = new Response();
$response->setContent( $json );
$response->headers->set( "Content-Type", "application/json" );
return $response;
}
}
?>
Change the namespace to this:
namespace AppBundle\Services;
instead of this:
namespace AppBundle\Services\Helpers;
You have to change namespace of class Helpers
:
namespace AppBundle\Services;