当我使用:
php app/console doctrine:fixtures:load --fixtures=/var/www/Symfony/src/BISSAP/ForumBundle/DataFixtures/ORM**
我收到以下错误:
PHP Catchable 致命错误:传递给 BISSAP\ForumBundle\Entity\Forum::setCategory() 的参数 1 必须是 BISSAP\ForumBundle\Entity\Category 的实例,给定 null,在 /var/www/Symfony/src/BISSAP/ 中调用第 40 行的 ForumBundle/DataFixtures/ORM/LoadForum.php 并在第 184 行的 /var/www/Symfony/src/BISSAP/ForumBundle/Entity/Forum.php 中定义
我的夹具 - LoadForum.php:
<?php
namespace 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 Symfony\Bundle\FrameworkBundle\Controller\Controller;
class LoadForum extends Controller implements FixtureInterface
{
public function load(ObjectManager $manager)
{
$data=array(array('NAME','DESCRTIPTION','60',$manager->getRepository('BISSAPForumBundle:Category')->find('1')),
array('NAME2','DESCRTIPTION2','60',$manager->getRepository('BISSAPForumBundle:Category')->find('2')));
foreach ($data as $for) {
$forum = new Forum();
$forum->setName($for[0]);
$forum->setDescription($for[1]);
$forum->setOrdre($for[2]);
$forum->setCategory($for[3]);
$manager->persist($forum);
}
$manager->flush();
}
}