Symfony 和 Doctrine:项目结构约定
我使用 symfony 的 ProjectConfiguration.class.php 来配置原则的连接:
public function configureDoctrineConnectionCertby(Doctrine_Connection $conn)
{
$conn->setListener(new MyListner());
}
Where should I Define MyListner class inside a symfony project?
I use symfony's ProjectConfiguration.class.php for configuring doctrine's connection:
public function configureDoctrineConnectionCertby(Doctrine_Connection $conn)
{
$conn->setListener(new MyListner());
}
Where should I define MyListner class within a symfony project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该为所有 Doctrine 文件创建一个
lib/Doctrine
(或lib/doctrine/Doctrine
- 这是 Symfony 在 sfDoctrineGuardPlugin 内部所做的)文件夹。由于监听器是 Doctrine 文件而不是 Symfony 文件,因此您应该遵循它们的 Doctrine 命名约定。在这种情况下,MyListener 将进入:/lib/Doctrine/Record/Listener/MyListener.php
这是执行此操作的“正确”方法。如果您只是将文件放入
/lib
或/lib/Doctrine
中,那么当然可以工作。You should make a
lib/Doctrine
(orlib/doctrine/Doctrine
- this is what Symfony does inside of sfDoctrineGuardPlugin) folder for all Doctrine files. Since Listeners are Doctrine files not Symfony files, you should be following Doctrine naming conventions for them. In this case, MyListener would go in:/lib/Doctrine/Record/Listener/MyListener.php
This is the "proper" way to do this. It would of course work if you simply threw the files in
/lib
or/lib/Doctrine
.如果您希望侦听器在项目级别可用,请将其放在 /project/lib/ 文件夹中。如果您只想在模块级别使用它,请将其放在 /project/apps/module/lib/ 文件夹中。
If you want your listener to be available at the project level, put it in the /project/lib/ folder. If you just want it to be available at the module level, put it in the /project/apps/module/lib/ folder.