Doctrine248 command line tool to generate yml/xml/entities

Source: Internet
Author: User
: This article describes how to generate ymlxmlentities using the Doctrine248 command line tool. For more information about PHP tutorials, see. The tools directory of the Doctrine2 compressed package is used for some command line work. Here we will mainly talk about using tools to automatically generate yml/xml/entities from the table structure of the database, because writing those things is too time-consuming.

1. use the Doctrine orm: convert-mapping command to generate 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);
  
 

The above is help, and the following is an instance.

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

Here, the commands executed on linux are first cd to the/var/www/doctrine (some Cainiao asked me what cd is, for example, Mao is the directory ~~ What is cd? bye-bye, Baidu. Why is this directory? this is the project folder. In short, there is a doctrine package ). The preceding command omitted the explanation. the "xml" after the explanation indicates the file type generated, "config/xml/" indicates the xml storage directory, and -- from-database indicates that the file is generated from the database.

2. yml is generated, and entities are generated.

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

This is simple. my entities are placed under/var/www/doctrine/src for test purposes only, and the later architecture will change.

If you want to convert yml into yml and then generate entities, you cannot directly generate entities. However, I didn't succeed. What are possible operations?

There are too few articles about php orm, because it is not commonly used. to put it bluntly, php orm is not very useful and purely convenient.

The above introduces Doctrine248 command line tool to generate yml/xml/entities, including the content, hope to be helpful to friends interested in PHP tutorials.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.