propel / propel-service-provider
Propel 对 Silex 的集成。
Requires
- propel/propel1: ~1.6
- silex/silex: ~1.0
This package is auto-updated.
Last update: 2024-08-29 03:31:20 UTC
README
PropelServiceProvider 提供与 Propel 的集成。
参数
-
propel.path (可选): Propel.php 文件的路径。对于 PEAR 安装,通常是
propel
,而对于 Git 安装,通常是vendor/propel/runtime/lib
。默认为/full/project/path/vendor/propel/propel1/runtime/lib
。 -
propel.config_file (可选): Propel 配置文件的完整路径名称。默认为
/full/project/path/build/conf/projectname-conf.php
-
propel.model_path (可选): 模型类的路径。默认为
/full/project/path/build/classes
强烈建议为上述选项使用 绝对路径。
服务
不提供任何服务。
Propel 通过 使用 静态方法来自行配置和管理,因此没有服务被注册到应用程序中。实际上,PropelServiceProvider 类以更“Silex”的方式初始化 Propel。
注册
确保您在 vendor/propel
中放置了 Propel 的副本,或者通过 PEAR 或 Composer 安装它。
有关更多信息,请参阅 Propel 文档
<?php $app['propel.config_file'] = __DIR__.'/path/to/myproject-conf.php'; $app['propel.model_path'] = __DIR__.'/path/to/model/classes'; $app->register(new Propel\Silex\PropelServiceProvider());
或者,如果您通过 Git 在 vendor/propel
中安装了 Propel,并且使用默认的 Propel 生成器选项构建了您的模型
<?php $app->register(new Propel\Silex\PropelServiceProvider());
我们可以考虑“默认”的 Propel 生成器选项
-
将
build.properties
和schema.xml
文件放入主项目目录中,通常位于index.php
文件所在的目录。 -
在
build.properties
文件中,仅定义propel.database
、propel.project
和propel.namespace.autopackage
属性。
使用方法
您需要自行构建模型。根据 Propel 文档,您需要三个文件
-
schema.xml
包含您的数据库模式; -
build.properties
更多信息见下文; -
runtime-conf.xml
包含数据库配置。
使用 propel-gen
脚本创建所有文件(SQL、配置、模型类)。
默认情况下,PropelServiceProvider 依赖于您配置的 Silex 自动加载器以加载模型类。当然,Silex 自动加载器需要使用命名空间构建模型,因此请确保在 build.properties
文件中设置此属性
propel.namespace.autopackage = true The recommended configuration for your `build.properties` file is: propel.project = <project_name> propel.namespace.autoPackage = true propel.packageObjectModel = true # Enable full use of the DateTime class. # Setting this to true means that getter methods for date/time/timestamp # columns will return a DateTime object when the default format is empty. propel.useDateTimeClass = true # Specify a custom DateTime subclass that you wish to have Propel use # for temporal values. propel.dateTimeClass = DateTime # These are the default formats that will be used when fetching values from # temporal columns in Propel. You can always specify these when calling the # methods directly, but for methods like getByName() it is nice to change # the defaults. # To have these methods return DateTime objects instead, you should set these # to empty values propel.defaultTimeStampFormat = propel.defaultTimeFormat = propel.defaultDateFormat =
如果您计划不使用命名空间构建模型,则需要强制 Propel 使用其内部自动加载器。通过将选项 propel.internal_autoload
设置为 true
来执行此操作。
有关更多信息,请参阅 Propel 文档。