Symfony 方法返回stdClass而不是实体实例

Symfony 方法返回stdClass而不是实体实例,symfony,doctrine-orm,Symfony,Doctrine Orm,我四处搜索,没有找到对我有帮助的答案 我在symfony2中使用了条令,根据条令的文档,find方法应该返回null或实体的实例 以下代码在传递有效的客户机id并引发异常时返回stdClass。正在将实体管理器注入服务的构造函数 对对象使用注释检查可以正常工作,并且不会引发异常 $client = $this->em->find('Entity\Clients\Client', $clientId); \Doctrine\Common\Util\Debug::dump($clien

我四处搜索,没有找到对我有帮助的答案

我在symfony2中使用了条令,根据条令的文档,find方法应该返回null或实体的实例

以下代码在传递有效的客户机id并引发异常时返回stdClass。正在将实体管理器注入服务的构造函数

对对象使用注释检查可以正常工作,并且不会引发异常

$client = $this->em->find('Entity\Clients\Client', $clientId);

\Doctrine\Common\Util\Debug::dump($client);

//if (!is_object($client)) {
if (!$client instanceof Entity\Clients\Client) {
    throw new ClientDoesNotExistException($clientId);
}
nyone对此有解释吗?我是不是错过了一些基本的东西

谢谢

谢谢你,塞拉德。config.yml中的原则位如下

# Doctrine Configuration
doctrine:
    dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        # if using pdo_sqlite as your database driver, add the path in parameters.yml
        # e.g. database_path: "%kernel.root_dir%/data/data.db3"
        # path:     "%database_path%"

orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    auto_mapping: true
    filters:
        portal_filter:  path\to\BaseBundle\Filter\PortalFilter
        enabled:        true;'
Composer.json

{
"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
    "psr-0": { "": "src/", "SymfonyStandard": "app/" }
},
"require": {
    "php": ">=5.3.3",
    "symfony/symfony": "2.5.*",
    "doctrine/orm": "~2.2,>=2.2.3",
    "doctrine/doctrine-bundle": "~1.2",
    "twig/extensions": "~1.0",
    "symfony/assetic-bundle": "~2.3",
    "symfony/swiftmailer-bundle": "~2.3",
    "symfony/monolog-bundle": "~2.4",
    "sensio/distribution-bundle": "~3.0",
    "sensio/framework-extra-bundle": "~3.0",
    "incenteev/composer-parameter-handler": "~2.0",
    "sensio/generator-bundle": "~2.3",
    "friendsofsymfony/rest-bundle": "1.3.*",
    "jms/serializer-bundle": "0.13.0",
    "friendsofsymfony/user-bundle": "~2.0@dev",
    "friendsofsymfony/jsrouting-bundle": "1.5.3",
    "doctrine/migrations": "dev-master",
    "doctrine/doctrine-migrations-bundle": "dev-master",
    "dunglas/angular-csrf-bundle": "1.0.*@dev",
    "oldsound/rabbitmq-bundle": "1.3.*",
    "oyejorge/less.php": "~1.5",
    "nelmio/api-doc-bundle": "dev-master",
    "peekmo/jsonpath": "dev-master",
    "uecode/api-key-bundle": "dev-master",
    "aws/aws-sdk-php-zf2": "1.2.*"},
"require-dev": {
    "doctrine/doctrine-fixtures-bundle": "dev-master",
    "phpunit/phpunit": "3.7.*",
    "liip/functional-test-bundle":"dev-master"
},
"scripts": {
    "post-root-package-install": [
        "SymfonyStandard\\Composer::hookRootPackageInstall"
    ],
    "post-install-cmd": [
        "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles"
    ],
    "post-update-cmd": [
        "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
        "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles"
    ]
},
"config": {
    "bin-dir": "bin"
},
"extra": {
    "symfony-app-dir": "app",
    "symfony-web-dir": "web",
    "incenteev-parameters": {
        "file": "app/config/parameters.yml"
    },
    "branch-alias": {
        "dev-master": "2.5-dev"
    }
}
}
同样的问题,这次来自控制器。仅供参考,之前我将doctrine的实体经理注入到服务中,如下所示:

DocumentManager:
    class: DocumentHandlerBundle\Services\DocumentManager
    arguments: [@doctrine.orm.entity_manager]
在控制器中:

public function newDocumentAction() {          
    $em = $this->getDoctrine()->getManager();
    $entity = $em->find('Entity\Documents\Document', 1400);

    echo get_class($entity); // output: Entity\Documents\Document

    if ($entity instanceof Entity\Documents\Document) {
        echo "<p>YEYYY, we have an entity!!!</p>";
    } else {
        echo "<p>&/%#$&%#, not an entity!!!</p>";
    }
    return new Response('');
}

我猜您还有另一个包,其中包含一些专门的实体侦听器。或者你调整了你的条令配置以适应不寻常的情况。首先发布您的applications composer.json文件和app/config.yml.Thank Cerad的条令部分。将这些添加到我上面的问题中。因此,请在config.yml中注释掉过滤器内容,我打赌您将获得您的实体。然后去看看过滤器应该做什么。它可能会拦截onLoad并将实体类转换为std类。@Cerad-谢谢你的提示。但它没有起作用。我仍然得到一个标准类作为find的输出。@Cerad-当我按照上面的代码直接从控制器运行代码时,我遇到了同样的问题。。。真奇怪,谢谢你的帮助。