欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

我們在使用symfony的時候,有時需要在數(shù)據(jù)庫中內置一些數(shù)據(jù),那么我們如何在doctrine中設置呢?

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

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

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

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

composer update doctrine/doctrine-fixtures-bundle

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

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

第四步,在需要內置數(shù)據(jù)的bundle下創(chuàng)建一個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í)行內置數(shù)據(jù)命令:

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

此命令有以下三個參數(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博客 ,轉載時請注明出處及相應鏈接。

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

希望本文所述對大家基于Symfony框架的PHP程序設計有所幫助。

相關文章

  • php生成圖形(Libchart)實例

    php生成圖形(Libchart)實例

    統(tǒng)計圖形就我們會常到的數(shù)據(jù)圖形了,如果三個數(shù)組以圖形顯示或樓盤以圖形走向我們都會要用到圖形,下面介紹一個php LIbchart圖形生成類
    2013-11-11
  • 簡單實現(xiàn)PHP留言板功能

    簡單實現(xiàn)PHP留言板功能

    這篇文章主要教大家如何簡單實現(xiàn)PHP留言板功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • thinkphp分頁實現(xiàn)效果

    thinkphp分頁實現(xiàn)效果

    大量數(shù)據(jù)的顯示就需要對內容進行分頁,本文章就是就是介紹thinkphp分頁進行整理,有需要的朋友一起來了解一下。
    2016-10-10
  • php共享內存段示例分享

    php共享內存段示例分享

    在asp.net和java中都有共享內存,php除了可以使用Memcached等方式變通以外其實php也是支持共享內存的,下面使用shmop來實現(xiàn)這個功能
    2014-01-01
  • smarty簡單模板變量輸出方法

    smarty簡單模板變量輸出方法

    這篇文章主要介紹了smarty簡單模板變量輸出方法,涉及Smarty模板中數(shù)組的定義、使用及assign方法進行變量替換的相關技巧,需要的朋友可以參考下
    2016-07-07
  • php 取得瑞年與平年的天數(shù)的代碼

    php 取得瑞年與平年的天數(shù)的代碼

    利用php如何取得取得瑞年與平年中每月份的天數(shù),如下函數(shù)
    2009-08-08
  • [php] 我的微型論壇的簡單教程[已完成]

    [php] 我的微型論壇的簡單教程[已完成]

    [php] 我的微型論壇的簡單教程[已完成]...
    2007-05-05
  • PHP單例模式與工廠模式詳解

    PHP單例模式與工廠模式詳解

    這篇文章主要為大家詳細介紹了PHP單例模式與工廠模式的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • Symfony2安裝第三方Bundles實例詳解

    Symfony2安裝第三方Bundles實例詳解

    這篇文章主要介紹了Symfony2安裝第三方Bundles的方法,結合實例形式分析了Symfony2通過composer來安裝Bundle的具體步驟與相關技巧,需要的朋友可以參考下
    2016-02-02
  • PHP 文件上傳限制問題

    PHP 文件上傳限制問題

    這篇文章主要介紹了PHP 文件上傳限制問題,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-09-09

最新評論