繁体   English   中英

负载声明必须与…FixtureInterface :: load()兼容

[英]Load declaration must be compatible with …FixtureInterface::load()

我正在创建一个需要加载功能的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);
}

您缺少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();
    }

}

我有相同的错误消息,但使用OrderedFixture接口而不使用FixtureInterface Itelf。

就我而言,它与load()方法无关。 实际上,我已经省略了添加方法getOrder()的操作,该方法在接口中是必需的。

因此,此错误消息导致我有一个错误的提示。 所以有时候要当心:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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