Doctrine2压缩包的tools目录用来做一些命令行工作。这里主要说一下通过tools,把数据库的表结构自动生成yml/xml/entities,原因是写那些东西太浪费时间了有木有。
1.通过Doctrine 的orm:convert-mapping命令生成xml/yml
Usage: orm:convert-mapping [options] [--] <to-type> <dest-path> orm:convert:mapping Arguments: 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 debug Help: 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卵用不大,纯粹方便
相关推荐
- **安装**: 可以通过Composer(PHP的包管理器)来安装Doctrine Cache,`composer require doctrine/cache`。 - **配置**: 配置所需的Cache Provider,并指定相应的连接参数。 - **实例化**: 创建Cache实例,选择...
用Doctrine DBAL替换PDO 关于这个例子 PDO是用于数据库PHP数据抽象库,自从它在PHP 5中启动以来,如何处理与数据库的通信的方式已经改变,带来了许多改进。 显然,第一个方法是将过程操作放在一边,而将重点放在面向...
- Doctrine提供了一个强大的命令行工具,可用于执行各种任务,如数据库操作、模型生成、数据填充等。 总结来说,Doctrine 1.0.0作为PHP ORM框架,旨在简化数据库操作,提升开发效率。通过其详尽的手册,开发者可以...
:gem_stone: Simple MySQLi Class ...and secure interaction with your database using mysqli_* functions at its core. This is perfect for small scale applications such as cron jobs, facebook canvas ...
Doctrine Cache是PHP开发中的一个重要工具,它提供了一套完整的缓存解决方案,使得开发者可以轻松地在项目中集成缓存功能,提高应用程序的性能和响应速度。这个类库支持多种缓存后端,包括但不限于内存(如APC、...
一旦安装和配置完成,就可以通过 Laravel 的 Artisan 命令行工具来使用这些生成器。例如,可以创建一个新的 Doctrine 实体类: ``` php artisan doctrine:generate:entity User --fields="name:string, email:...
- **命令行工具**:提供了各种命令行工具,帮助开发者进行数据库迁移、元数据生成等工作。 - **事务与并发控制**:探讨了事务处理、锁定机制等并发控制相关的主题。 - **过滤器**:讲解了如何使用过滤器对查询结果...
使用 Doctrine 的命令行工具生成数据库表,然后通过`doctrine:schema:update --force`更新数据库结构。在控制器中,使用 Doctrine 的`EntityManager`进行CRUD(创建、读取、更新、删除)操作。 ### 9. 测试与部署 ...
总结,`lumen-oauth2-doctrine` 是 Lumen 平台上实现 OAuth2 授权的一个强大工具,结合 Doctrine ORM 可以轻松管理和存储 OAuth2 数据。通过理解和正确使用这个模块,可以为你的 Lumen 应用提供安全、可扩展的 API ...
在Laravel框架中,开发通常涉及数据库操作,而Doctrine是一个流行的ORM(对象关系映射)工具,用于将数据库操作转化为面向对象的代码。本主题"**Laravel开发-doctrine-entity-factories**"聚焦于如何利用 Doctrine ...
// 更多缓存驱动请移步 https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/caching.html$redisCache = new \Doctrine\Common\Cache\RedisCache();//$redisCache->setRedis($redis); // ...
此外,Laravel的Artisan命令行工具提供了丰富的命令,用于生成控制器、模型、迁移等,加速了开发过程。 Doctrine ORM在Laravel中的应用,主要是通过Eloquent ORM,这是Laravel自带的一个轻量级ORM。然而,有些...
1. 安装:通过Composer安装包,运行`composer require doctrine/orm laravel-doctrine/orm laravel-doctrine/behaviours`。 2. 配置:配置Doctrine连接,替换默认的Eloquent ORM。在`config/app.php`中注册`...
- SVN:使用SVN命令行工具从官方仓库检出最新版本。 - PEAR Installer:如果服务器上已安装PEAR,可通过PEAR安装器安装Doctrine。 - 直接下载:访问官方网站下载最新发布的包,解压后即可使用。 2. **包含库文件...
解压后,通过运行`bin/console`或`vendor/bin/symfony`命令,可以访问Symfony命令行工具,执行如创建控制器、生成实体、数据库迁移等操作。 学习Symfony时,了解其核心概念如服务容器、事件调度、依赖注入和控制器...
8. **迁移与schema管理**: Doctrine 提供了命令行工具来管理数据库结构的迁移,类似于Laravel的`migrations`,方便你在开发过程中调整数据库结构。 在"laravel-doctrine-master"这个文件夹中,很可能是包含了完整...
对于现有数据库,通过`Doctrine`的工具可以自动生成相应的模型类;对于新项目,开发者可以根据业务需求定义模型,包括字段类型、长度、默认值等。同时,`Doctrine`支持自动加载模型,减少了代码冗余,提高了开发效率...
7. **查询构建器(QueryBuilder)**:提供了一种灵活的方式来构建SQL查询,可以生成复杂的SELECT、UPDATE和DELETE语句,避免直接编写SQL。 8. **Repository**:自定义仓储类可以扩展默认行为,实现特定的查找或业务...