【问题标题】:Load declaration must be compatible with ...FixtureInterface::load()加载声明必须与 ...FixtureInterface::load() 兼容
【发布时间】:2012-02-15 14:58:48
【问题描述】:

我正在创建一个需要加载函数的 Doctrine 数据夹具。我从字面上复制了 FixtureInterface.php 的方法,但不知何故我的夹具的 load() 不同。

PHP Fatal error:  Declaration of PastonVerBundle\DataFixtures\ORM\LoadTimeZoneData::load() must be compatible with that of Doctrine\Common\DataFixtures\FixtureInterface::load() in /var/www/symfony/src/Paston/VerBundle/DataFixtures/ORM/LoadTimeZoneData.php on line 9

我的负载:

<?php

namespace PastonVerBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Paston\VerBundle\Entity\TimeZone;

class LoadTimeZoneData 
    implements FixtureInterface {

    function load(ObjectManager $manager) {

        $z = new \TimeZone();
        $z->setName('Timezone');
        $manager->persist($z);
        $manager->flush();
    }

}

?>

从 FixtureInterface.php 加载

namespace Doctrine\Common\DataFixtures;

use Doctrine\Common\Persistence\ObjectManager;

/**
 * Interface contract for fixture classes to implement.
 *
 * @author Jonathan H. Wage <jonwage@gmail.com>
 */
interface FixtureInterface
{
    /**
     * Load data fixtures with the passed EntityManager
     *
     * @param Doctrine\Common\Persistence\ObjectManager $manager
     */
    function load(ObjectManager $manager);
}

【问题讨论】:

    标签: php symfony doctrine-orm


    【解决方案1】:

    你错过了use Doctrine\Common\Persistence\ObjectManager;

    namespace PastonVerBundle\DataFixtures\ORM;
    
    use Doctrine\Common\DataFixtures\FixtureInterface;
    use Paston\VerBundle\Entity\TimeZone;
    use Doctrine\Common\Persistence\ObjectManager;
    
    class LoadTimeZoneData 
        implements FixtureInterface {
    
        function load(ObjectManager $manager) {
    
            $z = new \TimeZone();
            $z->setName('Timezone');
            $manager->persist($z);
            $manager->flush();
        }
    
    }
    

    【讨论】:

      【解决方案2】:

      我收到了相同的错误消息,但使用了 OrderedFixture 接口 不使用 FixtureInterface 本身。

      在我的情况下,它确实与 load() 方法无关。 事实上,我没有添加 getOrder() 方法,它是 界面中的必填项。

      因此,此错误消息使我得到了错误的提示。所以有时要小心:)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-07-01
        • 2013-10-08
        • 2011-04-04
        • 1970-01-01
        • 1970-01-01
        • 2020-07-01
        相关资源
        最近更新 更多