Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony controller as service如何与调用方法一起工作?_Service_Symfony - Fatal编程技术网

Symfony controller as service如何与调用方法一起工作?

Symfony controller as service如何与调用方法一起工作?,service,symfony,Service,Symfony,例如,在以下代码中: /** *@Route(“/patients”,service=“bundle1.controller.patient.index”) */ 最终类索引控制器 { 私人路由器; 私人工厂; 私有$templating; 私人$patientFinder; 公共函数构造(RouterInterface$router、FormFactoryInterface$formFactory、EngineInterface$Templateing、PatientFinder$Patien

例如,在以下代码中:

/**
*@Route(“/patients”,service=“bundle1.controller.patient.index”)
*/
最终类索引控制器
{
私人路由器;
私人工厂;
私有$templating;
私人$patientFinder;
公共函数构造(RouterInterface$router、FormFactoryInterface$formFactory、EngineInterface$Templateing、PatientFinder$PatientFinder)
{
$this->router=$router;
$this->formFactory=$formFactory;
$this->templating=$templating;
$this->patientFinder=$patientFinder;
}
/**
*@Route(“,name=“患者索引”)
*/
公共函数调用(请求$Request):响应
{
$form=$this->formFactory->create(PatientFilterType::class,null[
“操作”=>this->router->generate('patients_index'),
'method'=>Request::method\u GET,
]);
$form->handleRequest($request);
$patients=$this->patientFinder->matching($form->getData()?:[]);
返回$this->templating->renderResponse('patient/index.html.twig'[
'form'=>$form->createView(),
“患者”=>$患者,
]);
}
}
为什么
\uu invoke
的路由注释为空?。
此控制器的生命周期是什么?我的意思是,Symfony什么时候创建对象,什么时候执行类来使用
\u invoke

@Route
注释意味着类的主路径之后没有任何东西是
/patients
\uu invoke
是一个神奇的PHP方法,当您将类作为函数调用时(不提供任何方法)会执行该方法。 因此,当您点击路径
/patients
或从任何代码调用服务时,将执行
\u invoke
方法