I have 5 class Categoria, Produto, Subcategoria, Subproduto and Comanda and for execute search in all classes i try make a service like:
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class AccessClassController extends Controller{
/**
* Retorna todas as categorias ativas
*/
public function CategoriasAtivasAction()
{
$em = $this->getDoctrine()->getManager();
$categorias = $em->getRepository('AppBundle:Categoria')->findByAtivo(1);
return $categorias;
}
}
And i try access the service on ComandaController
class ComandaController extends Controller
{
...
public function newAction(Request $request, $id)
{
$comanda = new Comanda();
$categorias = $this->get('categorias.ativas')->CategoriasAtivasAction();
...
Then symfony return error
Call to a member function has() on null
500 Internal Server Error - FatalThrowableError
My services.yml has
services:
categorias.ativas:
class: AppBundle\Controller\AccessClassController
Whats wrong?