1 php dependency-injection controller symfony
是的 - 我已经搜索了一个答案并花了几个小时与谷歌.但麻烦仍然存在
class IndexController extends Controller\CommonController
{
private $container;
public function __construct(Container $container) {
$this->container = $container;
}
Run Code Online (Sandbox Code Playgroud)
在config.yml中
shop.website.index_controller:
class: %shop.website.index_controller%
parent: shop.common.common_controller
arguments: [@service_container]
Run Code Online (Sandbox Code Playgroud)
和
可捕获的致命错误:传递给Shop\WebSiteBundle\Controller\IndexController :: __ construct()的参数1必须实现接口Symfony\Component\DependencyInjection\ContainerInterface,没有给出,在I:\ sf2\www\vendor\symfony\symfony\src中调用第77行的Symfony\Bundle\FrameworkBundle\Controller\ControllerResolver.php,在I:\ sf2\www\src\Shop\WebSiteBundle\Controller\IndexController.php第13行中定义
任何人都可以解释错误在哪里?
请在yml/annotaions中配置(导致配置的不同类型让我发疯)
提前致谢
PS>更新了代码ID
services:
shop.common.common_controller:
abstract: true
class: %shop.common.common_controller%
arguments: ["@templating"]
Run Code Online (Sandbox Code Playgroud)
和
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
class CommonController
{
protected $templating;
public function __construct(EngineInterface $templating)
{
$this->templating = $templating;
}
Run Code Online (Sandbox Code Playgroud)
相同的结果(
您是如何在路线中配置控制器的?
我有一种感觉,你没有使用"控制器即服务"表示法:
my_controller:
pattern: /
defaults: { _controller: shop.website.index_controller:indexAction }
Run Code Online (Sandbox Code Playgroud)
此语法与默认路由语法不同.看看这里.
| 归档时间: |
|
| 查看次数: |
4147 次 |
| 最近记录: |