-2

i have this controller

namespace InicioBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use EntidadesBundle\Entity\Usuarios;
use Symfony\Component\HttpFoundation\Session\Session;
class DefaultController extends Controller
{
    private $session;

    public function __construct(){
        $this->session = new Session();
    }

   ..... 

        public function ver_rol($rol){
        if($this->sacarRol() === $rol){ 
                 return true;
             }else{
                 return false;
             }
    }

}

and in the services.yml , i got this:

parameters:
    #parameter_name: value

services:
    app.rolSession:
        class: InicioBundle\Controller\DefaultController
        arguments: ["i dont know how get paramets"]

the problem is that it doesnt work, symfony return an error FileLoaderLoadException, that the services.yml does not caontain valid YAML

1 Answers1

0

There is a space before parameters: in your services.yml file, maybe remove that and your yaml should be valid.

Also if you are passing no arguments to constructor you can just delete arguments: ["null"]

One more thing, IIRC you need to add FQCN as class name, so class: InicioBundle\Controller\Default => class: InicioBundle\Controller\DefaultController

While we are at the subject, you can type hint Request in your action and use it to getSession() or maybe inject @session service to your controller

kunicmarko20
  • 2,095
  • 2
  • 15
  • 25
  • Hi!, thaks for help, do you know how i can send arguments? – ANDRES FERNANDO MARTINEZ VALEN Sep 18 '17 at 22:07
  • @ANDRESFERNANDOMARTINEZVALEN in your argumenta array you can do `arguments: ['@session']` and the you have to add parameter to your conatructor, I suggest you read the documentation as someone suggested because this are pretty basic stuff and Symfony has best documentation – kunicmarko20 Sep 19 '17 at 03:42