加载声明必须与兼容..FixtureInterface::load()



我正在创建一个需要加载函数的Doctrine数据固定装置。我从FixtureInterface.php中直接复制了该方法,但不知何故,我的fixture的load()有所不同。

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

我的负载:

<?php
namespace PastonVerBundleDataFixturesORM;
use DoctrineCommonDataFixturesFixtureInterface;
use PastonVerBundleEntityTimeZone;
class LoadTimeZoneData 
    implements FixtureInterface {
    function load(ObjectManager $manager) {
        $z = new TimeZone();
        $z->setName('Timezone');
        $manager->persist($z);
        $manager->flush();
    }
}
?>

从FixtureInterface.php 加载

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

您缺少use DoctrineCommonPersistenceObjectManager;

namespace PastonVerBundleDataFixturesORM;
use DoctrineCommonDataFixturesFixtureInterface;
use PastonVerBundleEntityTimeZone;
use DoctrineCommonPersistenceObjectManager;
class LoadTimeZoneData 
    implements FixtureInterface {
    function load(ObjectManager $manager) {
        $z = new TimeZone();
        $z->setName('Timezone');
        $manager->persist($z);
        $manager->flush();
    }
}

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

在我的例子中,它实际上与load()方法无关。事实上,我忽略了添加方法getOrder(),它是接口中的强制项。

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

相关内容

  • 没有找到相关文章