Doctrine248 命令列工具產生yml/xml/entities

來源:互聯網
上載者:User
Doctrine2壓縮包的tools目錄用來做一些命令列工作。這裡主要說一下通過tools,把資料庫的表結構自動產生yml/xml/entities,原因是寫那些東西太浪費時間了有木有。

1.通過Doctrine 的orm:convert-mapping命令產生xml/yml

Usage:  orm:convert-mapping [options] [--]    orm:convert:mappingArguments:  to-type                        The mapping type to be converted.  dest-path                      The path to generate your entities classes.Options:      --filter=FILTER            A string pattern used to match entities that should be processed. (multiple values allowed)      --force                    Force to overwrite existing mapping files.      --from-database            Whether or not to convert mapping information from existing database.      --extend[=EXTEND]          Defines a base class to be extended by generated entity classes.      --num-spaces[=NUM-SPACES]  Defines the number of indentation spaces [default: 4]      --namespace[=NAMESPACE]    Defines a namespace for the generated entity classes, if converted from database.  -h, --help                     Display this help message  -q, --quiet                    Do not output any message  -V, --version                  Display this application version      --ansi                     Force ANSI output      --no-ansi                  Disable ANSI output  -n, --no-interaction           Do not ask any interactive question  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debugHelp: Convert mapping information between supported formats.  This is an execute one-time command. It should not be necessary for you to call this method multiple times, especially when using the --from-database flag.  Converting an existing database schema into mapping files only solves about 70-80% of the necessary mapping information. Additionally the detection from an existing database cannot detect inverse associations, inheritance types, entities with foreign keys as primary keys and many of the semantical operations on associations such as cascade.  Hint: There is no need to convert YAML or XML mapping files to annotations every time you make changes. All mapping drivers are first class citizens in Doctrine 2 and can be used as runtime mapping for the ORM.  Hint: If you have a database with tables that should not be managed by the ORM, you can use a DBAL functionality to filter the tables and sequences down on a global level:      $config->setFilterSchemaAssetsExpression($regexp);

上面是help,下面來一個執行個體

/var/www/doctrine$ php vendor/bin/doctrine orm:convert-mapping xml config/xml/ --from-database

這裡linux上執行的命令,先cd到/var/www/doctrine下面(有的菜鳥問了,cd是個什麼東東,為毛是這個目錄~~cd是什麼呢,拜拜,這種問題百度去。為什麼是這個目錄呢,這是專案檔夾,總之這下面就有doctrine的包了)。前面命令省略解釋,解釋後面的“xml”意思是產生的檔案類型,“config/xml/”是xml存放目錄 ,--from-database的意思是從資料庫產生。

2.產生yml了,然後就要產生entities了

/var/www/doctrine$ php vendor/bin/doctrine orm:generate-entities src/ --regenerate-entities

這個簡單,我的entities放在/var/www/doctrine/src下面,純粹測試用,後期架構會變化的

要先產生yml再產生entities,無法直接產生entities,反正我沒成功,可能操作問題?

PHP ORM這個文章太少了,因為這個不常用,說白了PHP ORM卵用不大,純粹方便

以上就介紹了Doctrine248 命令列工具產生yml/xml/entities,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.