在symfony中扩展sfDoctrineRecord [英] Extending sfDoctrineRecord in symfony
问题描述
sfDoctrineRecord
类中。但是我不想这样做,当然,因为我的更改将会在升级时出现故障,而且我的更改也不会适用于其他项目。 如果我想要在symfony的所有实例类中添加一些功能,那么正确的方式是什么?
(PS当我说实例类时,我的意思是像 lib / model / doctrine / Customer.class.php
。
步骤:
-
创建myDoctrineRecord
抽象类myDoctrineRecord extends sfDoctrineRecord
{
public function commonRecordMethod(){}
}
我将这个文件放在lib / record中,但是你可以把它放在自动装载机看到的任何地方。
-
Set Symfony在你的ProjectConfiguration的configureDoctrine回调中使用这个类:
public function configureDoctrine(Doctrine_Manager $ manager)
{
sfConfig :: set('doctrine_model_builder_options',array('baseClassName'=> myDoctrineRecord));
}
就是这样! Symfony不是很棒吗:)
I've added some functionality to some of my instance classes in my symfony project that I want ALL of my instance classes to have. If I didn't have any qualms about editing the core symfony installation, I would just add my methods directly to the sfDoctrineRecord
class. But I don't want to do that, of course, because my changes would break on upgrade, plus my changes wouldn't port well to other projects.
If I want to add certain functionality to all my instance classes in symfony, what's the "right" way to do that?
(P.S. When I say "instance class", I mean something like lib/model/doctrine/Customer.class.php
.)
Steps:
Create myDoctrineRecord
abstract class myDoctrineRecord extends sfDoctrineRecord { public function commonRecordMethod() { } }
I place this file in lib/record, but you can put it anywhere that the autoloader will see it.
Set Symfony to use this class in the configureDoctrine callback of your ProjectConfiguration:
public function configureDoctrine(Doctrine_Manager $manager) { sfConfig::set('doctrine_model_builder_options', array('baseClassName' => 'myDoctrineRecord')); }
That's it! Isn't Symfony great? :)
这篇关于在symfony中扩展sfDoctrineRecord的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!