负载声明必须兼容... FixtureInterface :: load() [英] Load declaration must be compatible with ...FixtureInterface::load()

查看:150
本文介绍了负载声明必须兼容... FixtureInterface :: load()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am creating a Doctrine data fixture that needs a load function. I literal copied the method from FixtureInterface.php but somehow the load() of my fixture differs.

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加载

Load from 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);
}


推荐答案

您缺少使用Doctrine\Common\Persistence\ObjectManager;


You are missing 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();
    }

}

这篇关于负载声明必须兼容... FixtureInterface :: load()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆