最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Symfony2實(shí)現(xiàn)在doctrine中內(nèi)置數(shù)據(jù)的方法

 更新時(shí)間:2016年02月05日 09:41:41   作者:Terry  
這篇文章主要介紹了Symfony2實(shí)現(xiàn)在doctrine中內(nèi)置數(shù)據(jù)的方法,結(jié)合實(shí)例形式分析了在doctrine中內(nèi)置數(shù)據(jù)的具體步驟與相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例講述了Symfony2實(shí)現(xiàn)在doctrine中內(nèi)置數(shù)據(jù)的方法。分享給大家供大家參考,具體如下:

我們?cè)谑褂胹ymfony的時(shí)候,有時(shí)需要在數(shù)據(jù)庫(kù)中內(nèi)置一些數(shù)據(jù),那么我們?nèi)绾卧赿octrine中設(shè)置呢?

所幸,symfony已經(jīng)為我們封裝好了。這里,我們需要用到DoctrineFixturesBundle。

第一步,在composer.json中引入所需的DoctrineFixturesBundle:

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

第二步,執(zhí)行composer:

composer update doctrine/doctrine-fixtures-bundle

第三步,在內(nèi)核(app/AppKernel.php)中注冊(cè)此bundle:

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

第四步,在需要內(nèi)置數(shù)據(jù)的bundle下創(chuàng)建一個(gè)PHP類文件,如src/Acme/HelloBundle/DataFixtures/ORM/LoadUserData.php,其代碼如下:

// 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();
  }
}

第五步,通過console執(zhí)行內(nèi)置數(shù)據(jù)命令:

php app/console doctrine:fixtures:load #為防止數(shù)據(jù)庫(kù)中原先的值被清除,可使用 --append 參數(shù)

此命令有以下三個(gè)參數(shù):

fixtures=/path/to/fixture – Use this option to manually specify the directory where the fixtures classes should be loaded;
append – Use this flag to append data instead of deleting data before loading it (deleting first is the default behavior);
em=manager_name – 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
本文出自 IT985博客 ,轉(zhuǎn)載時(shí)請(qǐng)注明出處及相應(yīng)鏈接。

更多關(guān)于PHP框架相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php優(yōu)秀開發(fā)框架總結(jié)》,《codeigniter入門教程》,《CI(CodeIgniter)框架進(jìn)階教程》,《Yii框架入門及常用技巧總結(jié)》及《ThinkPHP入門教程

希望本文所述對(duì)大家基于Symfony框架的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

全州县| 枣庄市| 武乡县| 河北省| 重庆市| 泗洪县| 北碚区| 商河县| 合水县| 泉州市| 威远县| 万荣县| 平乐县| 垦利县| 常州市| 治县。| 龙胜| 邳州市| 子洲县| 黄浦区| 深圳市| 临夏县| 错那县| 浑源县| 浙江省| 天水市| 达拉特旗| 会同县| 甘德县| 芷江| 泰兴市| 彝良县| 韩城市| 芒康县| 定西市| 定陶县| 资溪县| 台前县| 巢湖市| 阳高县| 屏东市|