开发者

One action reused in multiple applications

I have a symfony application with two different applications (frontend, backend) but there is one action in common. Now I have duplicated its code in both apps but I don't like that at all.

Is there a way to reuse an action in multiple symf开发者_如何转开发ony applications?


The easiest way would be to make an actions base class in lib with the shared methods/actions. Then the modules that need to use this functionality can just extend that base class instead of sfActions.

You could also probably just use an event listener on method_not_found of sfComponent. But that may not work as expected if the method is an actual action (and it would also be available in all modules and all components without some special detection logic).

The most complicated way would be to make a Plugin. Of course that would require making the logic that works with any models dynamic so it can be configured or isolating the relevant parts of the schema to the plugin's schema.


Two more options:

1) if your are on Linux, make a symlink to your actions.class.php or even whole module, if you share the same templates.

cd apps/backend/modules/name
ln -s ../../frontend/modules/name name

2) if you have not gone too far in development, re-factor your project to have only ONE application (my favourite).


If you want to share a module (and hence also it's actions), the proper way is to create a plugin.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜