[英]Symfony 5.1 - An exception has been thrown during the rendering of a template ("The controller for URI "/_fragment" is not callable")
recently I update my symfony project (4.1) to 5.1, but my code throws an error when I try embed the controller in twig template:最近我将我的 symfony 项目 (4.1) 更新到 5.1,但是当我尝试将控制器嵌入到 twig 模板中时,我的代码抛出了一个错误:
An exception has been thrown during the rendering of a template ("The controller for URI "/_fragment" is not callable: Controller "SamAngularBundle:System:connectionInfo" does neither exist as service nor as class.").在渲染模板期间抛出异常(“URI“/_fragment”的控制器不可调用:控制器“SamAngularBundle:System:connectionInfo”既不作为服务也不作为类存在。”)。
But when I run the URL works fine: View screenshot但是当我运行 URL 时工作正常:查看屏幕截图
Controller code:控制器代码:
class SystemController extends \Symfony\Bundle\FrameworkBundle\Controller\AbstractController {
/**
* @Route("/angular/connection/info", name="url_angular_connection_info")
*/
public function connectionInfoAction() {
return $this->render("@SamAngular/System/connection_info.html.twig");
}
}
Template code:模板代码:
{# empty Twig template #}
<div class="template-foot">
{{render(controller('SamAngularBundle:System:connectionInfo'))}}
</div>
What's the problem?有什么问题?
The Bundle:controller:action
syntax was deprecated in 4.1 and removed in 5.0. Bundle:controller:action
语法在 4.1 中被弃用并在 5.0 中被移除。 It's been replaced by the controller::action
syntax .它已被
controller::action
语法取代。
The same syntax for templates was also dropped much earlier (referenced for completeness, you are already using the new template syntax).模板的相同语法也更早被删除(为了完整性参考,您已经在使用新的模板语法)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.