简体   繁体   中英

Symfony service container - Catchable Fatal Error - Argument passed to construct

I'm getting an error with using the Symfony service container. This is the error I'm getting:

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;
    }

I'm not sure what I'm doing wrong.

Thanks

Look at your uses :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM