扩展 MVC 模型原则的最简单方法
我正在开发自己的使用命名空间的框架。
Doctrine 已经集成到我的自动加载系统中,我现在正处于为我的应用程序创建模型系统的阶段
通常我会创建一个像这样的简单模型:
namespace Application\Models;
class Users extends \Framework\Models\Database{}
它将继承所有默认的数据库模型方法,但使用 Doctrine 我仍然了解它是如何工作的,因为它不仅仅是一个简单的 DBAL。
我需要了解我的类将扩展的学说部分是什么,我可以执行以下操作:
namespace Application\Models;
class Users Extends Doctrine\Something\Table
{
public $__table_name = "users";
}
因此在控制器中我将能够执行以下操作:
public function Display($uid)
{
$User = $this->Model->Users->findOne(array("id" => (int)$id));
}
任何人都可以帮助我解决这个问题吗?
Im developing my own framework that uses namespaces.
Doctrine is already integrated into my auto loading system and im now at the stage where ill be creating the model system for my application
Usually i would create a simple model like so:
namespace Application\Models;
class Users extends \Framework\Models\Database{}
which would inherit all the default database model methods, But with Doctrine im still learning how it all works, as its not just a simple DBAL.
I need to understand whats the part of doctrine my classes would extend where i can do the following:
namespace Application\Models;
class Users Extends Doctrine\Something\Table
{
public $__table_name = "users";
}
And thus within the controller i would be able to do the following:
public function Display($uid)
{
$User = $this->Model->Users->findOne(array("id" => (int)$id));
}
Anyone help me get my head around this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您提供的示例代码与原则 1 或原则 2 都不相似。默认情况下,原则 1 中的表扩展为 \Doctrine_Table。另外,数据库表名是在相应的模型文件中定义的,而不是作为表类本身的属性。我建议您至少阅读文档的前几章并查看其中的一些示例
http://www.doctrine-project.org/projects/orm/1.2/docs/manual/introduction/en
the sample code you supplied does not resemble either doctrine 1 or doctrine 2. by default, tables in doctrine 1 extend \Doctrine_Table. additionally the database table name is defined in the corresponding model file, not as a property of the table class itself. i suggest you read at least the first few chapters of the documention and look at some examples there
http://www.doctrine-project.org/projects/orm/1.2/docs/manual/introduction/en