-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

4

1 回答 1

0

parameters:您的文件中之前有一个空格services.yml,也许删除它并且您的 yaml 应该是有效的。

此外,如果您没有向构造函数传递任何参数,则可以删除arguments: ["null"]

还有一件事,IIRC 你需要添加 FQCN 作为类名,所以class: InicioBundle\Controller\Default=>class: InicioBundle\Controller\DefaultController

当我们讨论这个主题时,您可以在您的操作中输入提示 Request 并将其用于 getSession() 或者可能将@session服务注入您的控制器

于 2017-09-18T20:22:04.743 回答