使用简单设计模式而不是框架包含 Doctrine2 实体管理器的方法
我刚刚开始使用 Doctrine2,我注意到它是高度围绕设计模式构建的,因此我想获得一些关于如何使用更多设计模式围绕 Doctrine2 创建应用程序的想法。
例如,所有 Doctrine2 应用程序都将包含类似于
require '/Doctrine/Common/ClassLoader.php';
use Doctrine\ORM\EntityManager,
Doctrine\ORM\Configuration;
//...class loading and config stuff goes here
$connectionOptions = array(
'driver' => 'pdo_sqlite',
'path' => 'database.sqlite'
);
$em = EntityManager::create($connectionOptions, $config);
现在的 Symfony 之类的框架的文件或类,可以轻松访问 EntityManager,然后将该信息吐出到屏幕上。
但是,有些应用程序足够简单,不需要像 Symfony 这样的整个框架。您只想能够访问您的数据,然后将其吐出到视图/页面。
您能否提供一个使这成为可能的良好设计模式的示例?
我期待看到一些有趣的例子和想法,总的来说,这是很好的、扎实的面向对象 PHP 理论。
谢谢。
I am just starting out with Doctrine2 and I noticed that it is highly built around design patterns so I wanted to get some ideas on how to create an application around Doctrine2 using more design patterns.
For example, all Doctrine2 applications will contain a file or class similar to
require '/Doctrine/Common/ClassLoader.php';
use Doctrine\ORM\EntityManager,
Doctrine\ORM\Configuration;
//...class loading and config stuff goes here
$connectionOptions = array(
'driver' => 'pdo_sqlite',
'path' => 'database.sqlite'
);
$em = EntityManager::create($connectionOptions, $config);
Now a framework like Symfony will make it easy to access your EntitityManager and then spit that information out to the screen.
However, some applications are simple enough where an entire framework like Symfony is not necessary. You just want to be able to access your data and then spit it out to a view/ page.
Can you provide an example for a good design pattern that will make this possible?
I am looking forward to seeing some interesting examples and ideas, and in general just good solid Object Oriented PHP toughts.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试使用 DI 容器。如果您可以更深入地了解您的应用程序的工作原理,我可以提供更具体的解决方案。
一些应用程序足够简单,不需要像 Symfony 这样的整个框架
如果是这种情况,那么 Doctrine 2 也可能是多余的。
好资源
如果您想了解有关 DDD 和设计模式的更多信息,这里有一些很好的资源:
You could try using a DI Container. If you could provide a little more insight into how your application works I could provide a more specific solution.
some applications are simple enough where an entire framework like Symfony is not necessary
If that is the case, then Doctrine 2 is likely overkill as well.
Good resources
Here are some good resources if you want to learn more about DDD and design patterns: