我是symblog 2初學者,我正在按照Symblog2的教程:http://tutorial.symblog.co.uk/docs/doctrine-2-the-blog-model.html。用Doctrine 2使用燈具致命錯誤
我已經創建了我的數據模型,並嘗試使用Doctrine 2裝置將測試數據填充到我的數據庫。
我下載了必要的軟件包,並添加以下到我的autoload.php
:
'Doctrine\\Common\\DataFixtures' => __DIR__.'/../vendor/doctrine-fixtures/lib', 'Doctrine\\Common' => __DIR__.'/../vendor/doctrine-common/lib',
和follwing到AppKernel.php
:
new Symfony\Bundle\DoctrineFixturesBundle\DoctrineFixturesBundle(),
我的燈具類看起來是這樣的:
<?php
namespace Soccer\MainBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Soccer\MainBundle\Entity\Team;
class TeamFixtures implements FixtureInterface
{
public function load($manager)
{
$team1 = new Team();
$team1->setName('Poland');
$team1->setImg('./img/POL.png');
$team1->setKitHome('./img/POL_1.png');
$team1->setKitAway('./img/POL_2.png');
$manager->persist($team1);
$manager->flush();
}
}
當我嘗試運行php app/console doctrine:fixtures:load
,我得到以下異常:
Fatal error: Declaration of Soccer\MainBundle\DataFixtures\ORM\TeamFixtures::load()must be compatible with that of Doctrine\Common\DataFixtures\FixtureInterface::load() in D:\xampp\htdocs\soccertips\em-symfony\src\Soccer\MainBundle\DataFixtures\ORM\TeamFixtures.php on line 8
Call Stack:
0.0004 328688 1. {main}() D:\xampp\htdocs\soccertips\em-symfony\app\console:0
0.0283 2043272 2. Symfony\Component\Console\Application->run() D:\xampp\htdocs\soccertips\em-symfony\app\console:22
0.0344 2230520 3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() D:\xampp\htdocs\soccertips\em-symfony\vendor\symfony\src\Symfony\Component\Console\Application.php:118
3.3961 18394992 4. Symfony\Component\Console\Application->doRun() D:\xampp\htdocs\soccertips\em-symfony\vendor\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php:75
3.3998 18394992 5. Symfony\Component\Console\Command\Command->run() D:\xampp\htdocs\soccertips\em-symfony\vendor\symfony\src\Symfony\Component\Console\Application.php:194
3.4006 18395336 6. Symfony\Bundle\DoctrineFixturesBundle\Command\LoadDataFixturesDoctrineCommand->execute() D:\xampp\htdocs\soccertips\em-symfony\vendor\symfony\src\Symfony\Component\Console\Command\Command.php:224
3.4056 18499160 7. Doctrine\Common\DataFixtures\Loader->loadFromDirectory() D:\xampp\htdocs\soccertips\em-symfony\vendor\bundles\Symfony\Bundle\DoctrineFixturesBundle\Command\LoadDataFixturesDoctrineCommand.php:97
3.4084 18509624 8. require_once('D:\xampp\htdocs\soccertips\em-symfony\src\Soccer\MainBundle\DataFixtures\ORM\TeamFixtures.php') D:\xampp\htdocs\soccertips\em-symfony\vendor\doctrine-fixtures\lib\Doctrine\Common\DataFixtures\Loader.php:92
我理解錯誤消息,但在我看來,我的load()
方法與FixtureInterface::load
兼容。
有人能告訴我,我失蹤了什麼?我一步一步跟着教程。
您下載的是不能互相兼容的組件。請仔細檢查您是否下載了正確的代碼並在正確的版本/修訂版本中。 – hakre 2012-01-30 16:16:31
我使用'php bin/vendors install'命令從git下載了最新的修訂版,所以我認爲版本*應該*兼容 – 2012-01-30 16:36:31
那麼想想你想要什麼,PHP本身需要執行的東西告訴你,不一起工作。因此,PHP需要完成這項工作,可能更好地信任PHP?此外,我會仔細檢查自動加載器配置,並不是所有名稱空間的相同部分共享相同的目錄,而來自同一供應商,不是嗎?我可能是錯的,但這看起來有些可疑。 – hakre 2012-01-30 16:38:40