English 中文(简体)
Zend_DB and MVC model对数据库表
原标题:Zend_DB and MVC models matching database tables

我先从比尔·卡温(Zend_DB的候选者)那里读过一些与数据库表没有直接联系的模式。 (我认为,有些发展中国家有其模式,可直接延伸Zentd_tables,从而更难以增加 objects子的 objects子,这是有意义的。)

So what Bill Karwin was saying is that a Model has tables and isn t a table but I m still thinking the way I have it is correct as its designed in an object oriented manner.

例如(理由说明):

A Monster has 1:M Mouth. a Mouth has 1:M Tooth. 

因此,在我的数据库中,有5个表格:

Monster: id, name, type
MonsterMouth: id, monster_id, mouth_id
Mouth: id, size
MouthTeeth: id, mouth_id, tooth_id
Tooth: id, size, shape, sharpness

然后是3个班级:

class Model_Monster { 
    private $id, $name, $type, $mouths = array();
    public function __construct ($id) {
        // Set properties from DB for supplied ID
        // Go through DB and add the mouths based on monster ID
    }

    public function countTeeth () {
        // Loop through each $mouths as $mouth and call $mouth->getTotalTeeth();
    }
} 
class Model_MonsterMouth { 
    private $id, $size, $teeth = array(); 
    public function __construct($id) {
        // Set properties from DB for supplied ID
        // Go through DB and add the types of teeth for this mouth ID
    }

    public function getTotalTeeth () {
        // return sizeof($teeth);
    }

}
class Model_Tooth {
    private $id, $size, $shape, $sharpness;
    public function __construct($id) {
        // Populate details based on ID passed
    }
}

然后,我猜测计算牙齿和牙齿的方法。

$monsterId = 1;
$monster = new Monster($monsterId);
// Count total teeth
$totalTeeth = $monster->countTeeth();

因此,僧.可能有多种不同的口.,1口mouth可能有多种不同的牙齿。

After writing out this lengthy post I think I ve got it right and that Bill Karwin is talking about those who have 5 Models rather than 3...

页: 1

3个模型中的代码>2 用于储存许多其他类型的物体。

如果mon门在大约10种不同类型牙齿中的9-10克之间有10口mouth,这是否是一个业绩问题? 我指的是PHP。 如果一个物体有1-100k且在复合物品中添加1-100k,那么我就认为,我只应当拥有一个带有若干财产的物体,以表明有多少此类物品。

如果我听起来正确的话,也许会帮助一些与之有问题的其他人。

感谢:D Dom

最佳回答

在不希望将李扎德的口号放在法案中的情况下,我认为,与其说是许多人,他更谈的是,你应当把你关于商业模式的抽象概念与其基本表述分开。

例如,重要的是不要依赖这样一个事实,即你业务模式的田地名称与你的数据库/文件储存/网站服务中的田地相同,因为这样就非常困难。

还认为,如果你的模型想到像“未来”这样的领域,那是“第一民族”和“地名”的简单分类。 你可能真的不想把“未来”与数据库中的“第一Name”和“地名”一起储存起来,因为它重复了数据并做了更多的工作来不断更新,但是如果你的模型与基本代表非常紧密地联系在一起,你要么需要(a)在你的数据库中增加“未来”或(b)在你的模型中不出现“未来”。

By keeping a clean separation, you would be able to have "FullName" in your model and some piece of code that generated it, while just having "FirstName" and "Surname" in the database. Of course, it also makes it much easier to switch out the backend database technology, should you ever need to.

我认为,一个重要的见解是,《示范法》不仅仅是其所包含的领域,而且还是业务规则、验证和可能采取的行动。 表格只是储存支持这种行为所必需的领域。

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签