我正在使用 FosUserBundle 装饰基类 SecurityController:
namespace App\Controller;
use FOS\UserBundle\Controller\SecurityController as BaseController;
class SecurityController extends BaseController
{
public function renderLogin(array $data)
{
$template = sprintf('FOSUserBundle:Security:login.html.%s', $this->container->getParameter('fos_user.template.engine'));
. . .
在我的 Services.yaml 中:
App\Controller\SecurityController:
decorates: fos_user.security.controller
问题是我收到错误:
The parameter "fos_user.template.engine" must be defined.
与 renderLogin 方法中的行相关:
$template = sprintf('FOSUserBundle:Security:login.html.%s', $this->container->getParameter('fos_user.template.engine'));
如何获取这个缺失的参数?上面的行来自 Symfony2,现在我在 Symfony4 中使用它。
我应该注入(inject)fos_user.template.engine
还是有另一种语法可以将其放入方法中?
最佳答案
具体错误意味着fos_user.template.engine
参数未定义。
此参数是在旧版本的 FOS_User 上定义的,但不再定义,也不再需要。您可以在配置文件中将其定义为 twig
,但最好使用当前 FOS_User
使用的方法。
如果您检查 SecurityController 的 renderLogin()
方法,你正在装饰的类,你会发现它是这样的:
protected function renderLogin(array $data)
{
return $this->render('@FOSUser/Security/login.html.twig', $data);
}
将您的扩展方法基于此方法,您可以完全摆脱 $template = sprintf() ...
行。
例如:
protected function renderLogin(array $data) {
$data['foo'] = "bar";
// do whatever else you need to do
return parent::renderLogin($data);
}
关于php - Symfony 4 FosUserBundle Controller 装饰,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54826825/