我正在学习本教程:here,当我更改为AbstractController时,出现以下错误:
Compile Error: Declaration of App\Controller\LuckyController::render() must be compatible with Symfony\Bundle\FrameworkBundle\Controller\AbstractController::render(string $view, array $parameters = Array, ?Symfony\Component\HttpFoundation\Response $response = NULL): Symfony\Component\HttpFoundation\Response
所以我检查了原始方法并添加了缺少的参数,但是现在我得到了
Compile Error: Declaration of App\Controller\LuckyController::render(string $view, array $parameters = Array, ?Symfony\Component\HttpFoundation\Response $response = NULL) must be compatible with Symfony\Bundle\FrameworkBundle\Controller\AbstractController::render(string $view, array $parameters = Array, ?Symfony\Component\HttpFoundation\Response $response = NULL): Symfony\Component\HttpFoundation\Response
这是我的代码:
<?php
// src/Controller/LuckyController.php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class LuckyController extends AbstractController
{
/**
* @Route("/lucky/number")
*/
public function render(string $view, array $parameters = [], Response $response = null)
{
$number = random_int(0, 100);
return $this->render('lucky/number.html.twig', ['number' => $number]);
}
}
我做错了什么?
答案 0 :(得分:1)
好,所以我很傻。我应该将方法名称保留为“数字”