Symfony服务容器 - Catchable Fatal Error - 传递给构造的参数

时间:2015-03-31 13:22:53

标签: php symfony

使用Symfony服务容器时出错。这是我得到的错误:

Catchable Fatal Error: Argument 3 passed to housesBundle\Model\PropertyDetailsModel::__construct() must be an instance of
housesBundle\Model\AuditModel, instance of sharedBundle\Model\AuditModel given,
called in /var/www/anildave/symfony/app/cache/dev/appDevDebugProjectContainer.php   
on line 1876 and defined
500 Internal Server Error - ContextErrorException

services.yml

audit_model_service:
    class: sharedBundle\Model\AuditModel
    arguments: [@doctrine.dbal.default_connection]

property_details_model_service:
    class: housesBundle\Model\PropertyDetailsModel
    arguments: [@doctrine.dbal.default_connection,@request_stack,@audit_model_service]
    calls:
        - [ setContainer, [ @service_container ]]

PropertyDetailsModel.php

namespace housesBundle\Model;

use Doctrine\DBAL\Connection;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use sharedBundle\Model;
use sharedBundle\Helper;

class PropertyDetailsModel extends Controller
{
    private $connection;
    private $requestStack;
    private $auditModel;

    public function __construct(Connection $connection, RequestStack          $requestStack, AuditModel $auditModel)
    {
        $this->connection = $connection;
        $this->requestStack = $requestStack;
        $this->auditModel = $auditModel;
    }

我不确定我做错了什么。

由于

1 个答案:

答案 0 :(得分:1)

看看你的用途:

use Doctrine\DBAL\Connection;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use sharedBundle\Model;
use sharedBundle\Helper;
use sharedBundle\Model\AuditModel;     // <---- Look here, add this