trindade / my-sf-propel-o-r-m-plugin
我的symfony 1.x插件用于Propel。
Requires
- composer/installers: *
- propel/propel: ~2.0.0-alpha8
This package is not auto-updated.
Last update: 2024-09-19 15:12:19 UTC
README
通过分支1.6替换symfony的核心理解Propel插件,使用最新的Propel版本。
安装
Composer方式
将require添加到您的composer.json中。名称有点奇怪,但像这样Composer的symfony1安装器正确地将它大写。Composer会自动将它们安装到您的项目插件目录,并添加要求。
{
"config": {
"vendor-dir": "lib/vendor"
},
"require": {
"propel/sf-propel-o-r-m-plugin": "dev-master"
}
}
当然,不要忘记将Composer的自动加载器添加到您的ProjectConfiguration中。
// config/ProjectConfiguration.class.php require __DIR__ .'/../lib/vendor/autoload.php'; require_once dirname(__FILE__) .'/../lib/vendor/symfony/lib/autoload/sfCoreAutoload.class.php'; sfCoreAutoload::register(); class ProjectConfiguration extends sfProjectConfiguration { public function setup() { $this->enablePlugins(array( 'sfPropelORMPlugin', ... )); // mandatory because of the Composer vendor directory naming scheme sfConfig::set('sf_phing_path', sfConfig::get('sf_lib_dir') .'/vendor/phing/phing'); sfConfig::set('sf_propel_path', sfConfig::get('sf_lib_dir') .'/vendor/propel/propel1'); } }
Git方式
从GitHub克隆插件
git clone git://github.com/propelorm/sfPropelORMPlugin.git plugins/sfPropelORMPlugin
cd plugins/sfPropelORMPlugin
git submodule update --init
如果您使用Git作为项目的VCS,最好将插件作为子模块添加。
git submodule add git://github.com/propelorm/sfPropelORMPlugin.git plugins/sfPropelORMPlugin
git submodule update --init --recursive
由于Phing和Propel库都包含在插件中,您必须为插件初始化子模块。
SVN方式
通过subversion仓库安装插件
svn checkout https://github.com/propelorm/sfPropelORMPlugin/trunk plugins/sfPropelORMPlugin
安装Phing
和Propel
svn checkout http://phing.mirror.svn.symfony-project.com/tags/2.3.3/classes/phing lib/vendor/phing
svn checkout https://github.com/propelorm/Propel/tags/1.6.5 lib/vendor/propel
最后一步
禁用核心Propel插件并启用sfPropelORMPlugin
。此外,更改Propel和Phing库的位置。
// config/ProjectConfiguration.class.php class ProjectConfiguration extends sfProjectConfiguration { public function setup() { //setup the location for our phing and propel libs sfConfig::set('sf_phing_path', sfConfig::get('sf_root_dir').'/plugins/sfPropelORMPlugin/lib/vendor/phing/'); sfConfig::set('sf_propel_path', sfConfig::get('sf_root_dir').'/plugins/sfPropelORMPlugin/lib/vendor/propel/'); sfConfig::set('sf_propel_generator_path', sfConfig::get('sf_root_dir').'/plugins/sfPropelORMPlugin/lib/vendor/propel/generator/lib/'); $this->enablePlugins('sfPropelORMPlugin'); } }
可选:更新测试项目中propel
和phing
文件夹的引用。
// plugins/sfPropelORMPlugin/test/functional/fixtures/config/ProjectConfiguration.class.php class ProjectConfiguration extends sfProjectConfiguration { public function setup() { $this->enablePlugins(array('sfPropelORMPlugin')); $this->setPluginPath('sfPropelORMPlugin', realpath(dirname(__FILE__) . '/../../../..')); // SVN way //sfConfig::set('sf_propel_path', SF_DIR.'/../lib/vendor/propel'); //sfConfig::set('sf_phing_path', SF_DIR.'/../lib/vendor/phing'); // Git way sfConfig::set('sf_propel_path', realpath(dirname(__FILE__) . '/../../../../lib/vendor/propel')); sfConfig::set('sf_phing_path', realpath(dirname(__FILE__) . '/../../../../lib/vendor/phing')); }
在插件安装后,您应该更新插件资源
php symfony plugin:publish-assets
更改项目中config/propel.ini
文件中symfony行为的路径
// config/propel.ini propel.behavior.symfony.class = plugins.sfPropelORMPlugin.lib.behavior.SfPropelBehaviorSymfony propel.behavior.symfony_i18n.class = plugins.sfPropelORMPlugin.lib.behavior.SfPropelBehaviorI18n propel.behavior.symfony_i18n_translation.class = plugins.sfPropelORMPlugin.lib.behavior.SfPropelBehaviorI18nTranslation propel.behavior.symfony_behaviors.class = plugins.sfPropelORMPlugin.lib.behavior.SfPropelBehaviorSymfonyBehaviors propel.behavior.symfony_timestampable.class = plugins.sfPropelORMPlugin.lib.behavior.SfPropelBehaviorTimestampable
(重新)构建模型
php symfony propel:build --all-classes
Propel 1.6的新特性
Propel 1.6是Propel 1.4(symfony 1.3和1.4捆绑的版本)的向后兼容演进,它增加了一些非常有趣的功能。在这些功能中,您将找到本质上是加强版的new Propel Query API
。
// find the 10 latest books published by authror 'Leo' $books = BookQuery::create() ->useAuthorQuery() ->filterByFirstName('Leo') ->endUse() ->orderByPublishedAt('desc') ->limit(10) ->find($con);
Propel 1.6还支持多对多关系
、集合
、按需加载
、新的核心行为(见下文)、更好的Oracle支持,并且现在使用MIT许可证。
核心Propel行为
Propel 1.6将大多数常见行为捆绑在一个新的、强大的构建时间实现中。这些核心行为提供了更快的运行时执行速度以及修改数据模型的能力。
sfPropelORMPlugin
允许您从schema.yml
直接注册核心Propel行为。例如,从Section
模型创建树结构
propel: section: _attributes: { phpName: Section } _propel_behaviors: - nested_set id: ~ title: { type: varchar(100), required: true primaryString: true }
提示:请查看此插件源代码中的doc/schema.md
文件,以获取YAML模式格式的完整参考。
您也可以直接在propel.ini
配置文件中为所有模型注册行为。sfPropelORMPlugin
已经启用了symfony
和symfony_i18n
行为以支持symfony的行为系统和模型本地化功能,但您可以轻松添加您自己的。
propel.behavior.default = symfony,symfony_i18n,alternative_coding_standards,auto_add_pk
管理生成器扩展
插件捆绑了一个名为“admin15”的新管理生成器主题。此主题与sfPropelPlugin的管理生成器主题向后兼容,并基于新的Propel 1.6查询对象提供额外的功能。
列表视图增强
- 简单关联对象激活:您不需要编写自定义
doSelectJoinXXX()
方法来激活关联对象。with
设置比之前的peer_method
和peer_count_method
设置更强大,且更容易使用。 - 自定义查询方法:您可以通过设置
query_methods
参数来细化执行的查询,以显示列表视图。这样可以在不执行额外查询的情况下激活额外的列,或者预先过滤列表以隐藏用户不应看到的行。 - 所有列均可排序:虚拟列和外键列现在在列表视图中可以排序。您需要设置要使用的排序方法,但这只需要一行代码。不再有列标题无法点击排序的列表了!
- 轻松链接到过滤列表:使用新主题,创建到过滤列表视图的链接非常简单。只需添加 GET 参数,就像您在 symfony 1.2 的管理员生成器中所做的那样,它就会生效。
- 链接到另一个管理员模块:为了使外键列链接到另一个模块中相关对象的编辑视图,您不再需要创建部分。只需在 foreign key 字段配置中定义
link_module
设置,然后您就可以开始了。 - 简单自定义过滤器:一旦您能够利用生成的 Propel 查询类,添加自定义过滤器就变得非常简单。例如,您可以在两分钟内设置全文搜索输入,用单个过滤器替换多个文本过滤器,从而提高可用性。
- 自动排序链接:如果模块是在具有排序行为的模型上生成的,则自动添加移动记录上移和下移的动作。
过滤和编辑表单增强
- YAML 小部件自定义:
generator.yml
格式已扩展,允许在 YAML 中直接自定义小部件和验证器,无需编辑表单对象。您还可以在表单定义中的display
列表中安全地省略字段,而不会丢失数据。 - 纯文本字段:如果您想在表单中显示某些数据而不允许用户编辑它,请使用
type: plain
属性,就像在 symfony 1.2 的早期那样。这对于由模型管理的列非常有用,如created_at
和updated_at
列。
admin15
生成器主题的新选项已完全记录,并通过真实示例进行说明,在插件源代码中的 doc/admin_generator.md
文件中。
表单子框架修改
- 更新
sfWidgetFormPropelChoice
小部件:小部件现在使用新的查询 API。您可以通过执行自定义查询方法,使用新的query_methods
选项,更容易地自定义选项列表。 - 更新 Propel 验证器:
sfValidatorPropelChoice
和sfValidatorPropelUnique
都已更新,以使用新的 PropelQuery 对象,并接受类似于sfWidgetFormPropelChoice
的query_methods
选项。 - 纯文本小部件和验证器:这个新小部件允许在表单中显示字段,而不允许用户更改它。
- 简单关系内嵌:与主对象(例如,在
Post
表单中编辑Comments
)一起编辑相关对象是一件轻而易举的事情。新的sfFormPropel::embedRelation()
方法会完成所有工作,以获取相关对象,为每个对象构建表单,并将相关对象表单内嵌到主表单中。内嵌关系表单允许您不编写任何额外代码即可 编辑、添加 和 删除 相关对象。
class ArticleForm extends BaseArticleForm { public function configure() { $this->embedRelation('Book'); } }
Propel 小部件、验证器和表单类在插件源代码中的 doc/form.md
文件中已完全记录。
过滤子框架修改
现在您可以合并或嵌入过滤器到过滤器中,它即插即用。
class ArticleFilter extends BaseArticleFilter { public function configure() { $this->mergeForm(new AuthorFilter()); } }
路由修改
插件提供了两个新的路由类,分别是 sfPropelORMRoute
和 sfPropelORMRouteCollection
。这些类在用 propel 管理生成器构建的模型中默认使用。它们的行为与之前的 sfPropelRoute
类相似 - 只是不再使用 methods
选项了。取而代之的是,使用 query_methods
选项在调用 getObject()
和 getObjects()
时执行一系列任意的查询方法。
author: class: sfPropelORMRouteCollection options: model: author module: author prefix_path: /author column: id query_methods: object: [filterByIsPublished] list: [filterByIsPublished, orderByLastName] with_wildcard_routes: true
对于 query_methods
也可以有额外的参数数组。
author: class: sfPropelORMRouteCollection options: model: author module: author prefix_path: /author column: id query_methods: object: filterByIsPublished: [false] list: filterByIsPublished: [] orderBy: [LastName] with_wildcard_routes: true
sfPropelORMRoute
还使您在动作中的代码更容易阅读。您可以使用对象的路线的类名来调用一个getter,而不仅仅是调用 getObject()
。
public function executeShow(sfWebRequest $request) { // using sfPropelORMRoute with 'Author' as model $this->author = $this->getRoute()->getAuthor(); }
在 sfPropelORMRoute
和 sfPropelORMRouteCollection
中都添加了一个新选项,即 connection
选项,允许设置要使用的特定的 Propel 连接。示例
author_show: url: /author/:id class: sfPropelORMRoute param: { module: myModule, action: show } options: { model: Author, type: object, connection: my_connection }
author: class: sfPropelORMRouteCollection options: model: Author module: author prefix_path: /author column: id connection: my_connection with_wildcard_routes: true