Symfony2ʵÏÖÔÚdoctrineÖÐÄÚÖÃÊý¾ÝµÄ·½·¨

5年以前  |  阅读数:555 次  |  编程语言:PHP 

±¾ÎÄʵÀý½²ÊoÁËSymfony2ʵÏÖÔÚdoctrineÖÐÄÚÖÃÊý¾ÝµÄ½¨¡£*ÖÏi¸ø´o¼Ò¹(C)´o¼Ò²Î¿¼£¬¾ßÌaÈçÏ£º

ÎÒÃÇÔÚʹÓÃsymfonyµÄʱºo£¬ÓÐʱÐeÒªÔÚÊý¾Ý¿aÖÐÄÚÖÃÒ»Ð(C)Êý¾Ý£¬ÄÇôÎÒÃÇÈçºÎÔÚdoctrineÖÐÉeÖÃÄØ£¿

ËuÐÒ£¬symfonyÒѾ­ÎªÎÒÃÇ*a×°ºÃÁË¡£ÕaÀi£¬ÎÒÃÇÐeÒªÓõ½DoctrineFixturesBundle¡£

µÚÒ»²½£¬ÔÚcomposer.jsonÖÐÒýÈeËuÐeµÄDoctrineFixturesBundle£º


    {
      "require": {
        "doctrine/doctrine-fixtures-bundle": "2.2.*"
      }
    }

µÚ¶þ²½£¬Ö´ÐÐcomposer£º


    composer update doctrine/doctrine-fixtures-bundle

µÚÈý²½£¬ÔÚÄںˣ¨app/AppKernel.php£(C)ÖÐ×¢²a´Ëbundle£º


    // ...
    public function registerBundles()
    {
      $bundles = array(
        // ...
        new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
        // ...
      );
      // ...
    }

µÚËIJ½£¬ÔÚÐeÒªÄÚÖÃÊý¾ÝµÄbundleÏ´´½¨Ò»¸oPHPÀaÎļþ£¬Èçsrc/Acme/HelloBundle/DataFixtures/ORM/LoadUserData.php£¬Æa´uÂeÈçÏ£º


    // src/Acme/HelloBundle/DataFixtures/ORM/LoadUserData.php
    namespace Acme\HelloBundle\DataFixtures\ORM;
    use Doctrine\Common\DataFixtures\FixtureInterface;
    use Doctrine\Common\Persistence\ObjectManager;
    use Acme\HelloBundle\Entity\User;
    class LoadUserData implements FixtureInterface
    {
      /**
       * {@inheritDoc}
       */
      public function load(ObjectManager $manager)
      {
        $userAdmin = new User();
        $userAdmin->setUsername('admin');
        $userAdmin->setPassword('test');
        $manager->persist($userAdmin);
        $manager->flush();
      }
    }

µÚÎa²½£¬Í¨¹ýconsoleÖ´ÐÐÄÚÖÃÊý¾ÝÃuÁi£º


    php app/console doctrine:fixtures:load #Ϊ*ÀÖ¹Êý¾Ý¿aÖÐÔ­ÏȵÄÖµ±»Ça³ý£¬¿ÉʹÓà --append ²ÎÊý

´ËÃuÁiÓÐÒÔÏÂÈý¸o²ÎÊý£º

¨Cfixtures=/path/to/fixture ¨C Use this option to manually specify the directory where the fixtures classes should be loaded;
¨Cappend ¨C Use this flag to append data instead of deleting data before loading it (deleting first is the default behavior);
¨Cem=manager_name ¨C Manually specify the entity manager to use for loading the data.

¹Ù*½Îĵµ£ºhttp://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html

±¾ÎÄÓÀ¾ÃµØÖ*£ºhttp://blog.it985.com/6662.html
±¾Îijo×Ô IT985²(C)¿Í £¬×ªÔØʱÇe×¢Ã÷³o´¦¼°ÏaÓ¦Á´½Ó¡£

¸u¶a¹ØÓÚPHP¿o¼ÜÏa¹ØÄÚÈݸÐÐËȤµÄ¶ÁÕ߿ɲe¿´±¾Õ¾×¨Ìa£º¡¶phpÓÅÐa¿ª*¢¿o¼Ü×ܽa¡£¬¡¶codeigniterÈeÃŽ̡̳£¬¡¶CI(CodeIgniter)¿o¼Ü½ø½×½Ì³Ì¡£¬¡¶Yii¿o¼ÜÈeÃż°³£Óü¼ÇÉ×ܽa¡¼°¡¶ThinkPHPÈeÃŽ̡̳*

Ï£Íu±¾ÎÄËuÊo¶Ô´o¼Ò»uÓÚSymfony¿o¼ÜµÄPHP³ÌÐoÉe¼ÆÓÐËu°iÖu¡£

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例