加载时出现请求错误
Getting a request error on load
我最近进入了 Symfony,我正在关注一个(有点过时的)symblog 教程(source),现在在里面,他有一次从页面调用请求:
public function indexAction() {
$request = $this->getRequest();
if ($request->getMethod() == 'POST') {
//do stuff
}
return $this->render('BundleName:ClassController:view.html.twig');
));
}
我了解到不再支持,所以我将控制器作为参数移动(据我所知,由于 Symfony3.0 中的变化):
public function indexAction(Request $request) {
if($request->getMethod() == 'POST') {
//do stuff
}
return $this->render('BundleName:ClassController:view.html.twig');
}
但是如果我尝试 运行 这个,我仍然会收到以下错误:
Controller "BundleName\Controller\ClassController::indexAction()" requires that you provide a value for the "$request" argument (because there is no default value or because there is a non optional argument after this one).
这里有什么问题?我是否需要在控制器操作中实例化 $request
对象?某处是否有配置,我需要在其中实施新实施的属性?
你
use Symfony\Component\HttpFoundation\Request;
?
我最近进入了 Symfony,我正在关注一个(有点过时的)symblog 教程(source),现在在里面,他有一次从页面调用请求:
public function indexAction() {
$request = $this->getRequest();
if ($request->getMethod() == 'POST') {
//do stuff
}
return $this->render('BundleName:ClassController:view.html.twig');
));
}
我了解到不再支持,所以我将控制器作为参数移动(据我所知,由于 Symfony3.0 中的变化):
public function indexAction(Request $request) {
if($request->getMethod() == 'POST') {
//do stuff
}
return $this->render('BundleName:ClassController:view.html.twig');
}
但是如果我尝试 运行 这个,我仍然会收到以下错误:
Controller "BundleName\Controller\ClassController::indexAction()" requires that you provide a value for the "$request" argument (because there is no default value or because there is a non optional argument after this one).
这里有什么问题?我是否需要在控制器操作中实例化 $request
对象?某处是否有配置,我需要在其中实施新实施的属性?
你
use Symfony\Component\HttpFoundation\Request;
?