我正在创建一个需要加载功能的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);
}
答案 0 :(得分:6)
您遗失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();
}
}
答案 1 :(得分:0)
我有相同的错误消息,但使用OrderedFixture接口 不是FixtureInterface itelf。
在我的情况下,它确实与load()方法无关。 实际上我省略了添加方法getOrder() 在界面中是强制的。
因此,此错误消息导致我提示错误。所以有时要注意它:)