这可以作为普通控制器正常工作:
namespace BundleName\Bundle\SiteBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultController extends Controller
{
public function indexAction()
{
return $this->render('MyBundle:Default:index.html.twig', array("abc" => "test"));
}
}
...所以肯定通过这样做它应该简单地扩展控制器:
namespace BundleName\Bundle\SiteBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class ControllerExtension extends Controller
{
public function render(string $view, array $parameters = array(), Response $response = null)
{
return parent::render($view, $parameters, $response);
}
}
class DefaultController extends ControllerExtension
{
public function indexAction()
{
return $this->render('MyBundle:Default:index.html.twig', array("abc" => "test"));
}
}
..但我得到这个错误:
运行时注意: ...ControllerExtension::render() 的声明应该与 ...Bundle/SiteBundle/Controller/DefaultController.php 中的 Symfony\Bundle\FrameworkBundle\Controller\Controller::render() 的声明兼容
添加这个没有区别(这是我在某处看到的修复):
use Symfony\Component\HttpFoundation\Response