1. 云栖社区>
  2. PHP教程>
  3. 正文

error DataFixtures Symfony

作者:用户 来源:互联网 时间:2017-12-01 19:49:25

error DataFixtures Symfony - 摘要: 本文讲的是error DataFixtures Symfony, When I use “php app/console doctrine:fixtures:load –fixtures=/var/www/Symfony/src/BISSAP/ForumBundle/DataFixtures/ORM”

When I use “php app/console doctrine:fixtures:load –fixtures=/var/www/Symfony/src/BISSAP/ForumBundle/DataFixtures/ORM”

I get this message:

PHP Catchable fatal error: Argument 1 passed to BISSAP/ForumBundle/Entity/Topic::setForum() must be an instance of BISSAP/BodyConceptBundle/Entity/Forum, instance of Proxies__CG__/BISSAP/ForumBundle/Entity/Forum given, called in /var/www/Symfony/src/BISSAP/ForumBundle/DataFixtures/ORM/LoadTopic.php on line 33 and defined in /var/www/Symfony/src/BISSAP/ForumBundle/Entity/Topic.php on line 324

Fixture: LoadTopic.php

<?phpnamespace BISSAP/ForumBundle/DataFixtures/ORM;use Doctrine/Common/DataFixtures/FixtureInterface;use Doctrine/Common/Persistence/ObjectManager;use BISSAP/ForumBundle/Entity/Forum;use BISSAP/ForumBundle/Entity/Category;use BISSAP/ForumBundle/Entity/Topic;use Doctrine/Common/DataFixtures/AbstractFixture;use Doctrine/Common/DataFixtures/OrderedFixtureInterface;class LoadTopic extends AbstractFixture implements FixtureInterface, OrderedFixtureInterface{public function load(ObjectManager $manager){ $data = array( array('Title','BISSAP','60','25','slug-slug','genre','256','Comments',$this->getReference('BISSAP/ForumBundle/Entity/Forum-0')), array('Title2','BISSAP','60','25','slug-slug','genre','256','Comments',$this->getReference('BISSAP/ForumBundle/Entity/Forum-1'))); foreach ($data as $Top) { $topic = new Topic(); $topic->setTitle($Top[0]); $topic->setUser($Top[1]); $topic->setViewCount($Top[2]); $topic->setReplyCount($Top[3]); $topic->setSlug($Top[4]); $topic->setGenre($Top[5]); $topic->setLastPost($Top[6]); $topic->setContent($Top[7]); $topic->setForum($Top[8]); $manager->persist($topic); } $manager->flush();} public function getOrder(){ return 3;} }

Fixture: LoadForum.php

<?phpnamespace BISSAP/ForumBundle/DataFixtures/ORM;use Doctrine/Common/DataFixtures/FixtureInterface;use Doctrine/Common/Persistence/ObjectManager;use BISSAP/ForumBundle/Entity/Forum;use BISSAP/ForumBundle/Entity/Category;use Doctrine/Common/DataFixtures/AbstractFixture;use Doctrine/Common/DataFixtures/OrderedFixtureInterface;class LoadForum extends AbstractFixture implements FixtureInterface, OrderedFixtureInterface{ public function load(ObjectManager $manager) { $data = array(array('Vous debutez la musculation','Vous ne savez pas par où commencer, posez vos questions...','60',$this->getReference('BISSAP/ForumBundle/Entity/Category-0')),array('Entrainement','Questions liées à l/'entraienement et aux methodes...','60',$this->getReference('BISSAP/ForumBundle/Entity/Category-1')));$i=0;foreach ($data as $for) {$forum = new Forum();$forum->setName($for[0]);$forum->setDescription($for[1]);$forum->setOrdre($for[2]);$forum->setCategory($for[3]);$this->addReference('BISSAP/ForumBundle/Entity/Forum-'.$i,$forum);$i++;$manager->persist($forum); } $manager->flush(); } public function getOrder() {return 2; }}

Thanks U – Merci

以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索,以便于您获取更多的相关知识。