English 中文(简体)
有什么战略确保从一般搜索查询中适当分类?
原标题:What is a strategy to ensure proper subclasses from a generalized search query?

这里有一个普遍的设想。 我有“Tasks”,我有“Task” I ve创建了每个数据库表。 我还创建了一个模型,处理数据库的电子记录。

关于“Task Activities”,我有几类:创造、接受、评论、关闭。

Currently, I do something simple like $task = new Task($task_id); to grab the task from the database, and $task_events = new Tasks_Events($task_id); which grabs the events for that task. Then, I ve implemented Iterator so I can do foreach($task_events as $e) { ... } this is all working great.

然而,我发现,我需要一些专门的处理人员来从事一些类型的活动。 例如,我创立了任务,即:知识与知识。 任务——Events,并对评论活动类型进行一些额外的处理。 我现在认识到的是,在我收集活动资料时,我确实需要儿童类型,因此,如果要求采取某种方法,就应该从儿童类别中适当取胜。

这方面的一个快速例子:

class Model {
    public function __construct($search = null) {
        // Hypothetical example, basically query the DB and populate data.
        if (!is_null($search)) { $this->search($search); }
    }
    protected function onAfterUpdate() { }
}

class Tasks_Events extends Model {
    protected function onAfterUpdate() { /* Task Event Specific */ }
}

class Tasks_Events_Comments extends Tasks_Events {
    protected function onAfterUpdate() { /* Task Event Comment Specific */ }
}

然后是假设使用案例:

class Controller {
    public function updateEvent($task_id, $event_id, $params) {
        $task = new Tasks($task_id);
        $task_event = new Tasks_Events($event_id);

        // Some Analysis of Params
        $task_event->status = $new_status;
        $task_event->save();
    }
}

因此,就业和教育是关键。 采用这一方式,将要求任务——最新信息。

My question 是,我可以采用的一种模式、模式、哲学、方法,以便在我收集任务活动时,以及我就一项行动采取行动,即使我使用基类参考,我仍需要要求儿童班级职能。

我确实享有<代码>e = 新的任务——Events(3);$e->status = 4;$e->save();——我不喜欢的一种解决办法,是做如下的工作:$e = 任务_Events:Get($id); 任务_ 活动将查询数据库,确定类型,然后进行“巫术”,并创造适当的回归类型。

另一理由 我不喜欢这样说,因为我已经建立了冷却模式,如<代码>$tasks = 新的任务(通知(用户_id =>5,状况 =>任务:STATUS_OPEN);,它将建造适当的垃圾处理场,并为5用户开放的所有任务。 然后,我可以做<代码>foreach($tasks as$t){呼应t->subject;等。 因此,我很爱能够保持这种制度......但我不敢肯定,如果我想要利用遗产来替代型。

我恐怕我可能需要一个工厂模式,但我不希望我可能只是失踪。

P.S. 如果你能想到更好的所有权,就可自由改变。

最佳回答

感谢@Sam Dufel, 你的评论使我更深思熟虑,我在设计中发现了一大缺陷。

你提出了“task->getEvents()”的良好建议,但我放弃了我问题的关键(flaw?)点。 这可能也是我急切地陷入困境的原因。

从根本上讲,我执行《公约》的方式,而登机/开户可能是问题的根源。 自此以后,它积累了大量的原始记录。

那么,请说的是,在电梯中位居第2位。 电话:$this->records[$s->position]$! 因此,正如你可以看到的那样,我把自己描绘成一个角落。 即便有工厂模式,由于我是如何在“Events”(well... the Model) argh号任务中执行该装置的,这也会带来相当的工作。

Sorry to bother y all. Thanks for the thoughts.

Update: What I realize I did was combined a "DAO" with a "Model" with a "Model Collection" in effect. I m going to separate them. DAO->find() will return a Model Collection (which will be iterable), and DAO->findOne() which will return a Model. It was handy to have all three in one, but as my needs expanded, it was not very extensible.

问题回答

暂无回答




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

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 = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签