【发布时间】:2016-01-25 02:57:25
【问题描述】:
我正在开发一个基于 CakePHP 2.7.8 的服务请求应用程序。 我必须在用户区域显示提供请求服务的客户列表。
为此,我在数据库中有一个service_requests 表来跟踪用户提出的请求。
CREATE TABLE `service_requests` (
`id` char(36) NOT NULL,
`customer_id` char(36) DEFAULT NULL,
`customer_address_id` char(36) DEFAULT NULL,
`service_id` char(36) DEFAULT NULL,
`service_area_id` char(36) DEFAULT NULL,
`status_code` int(11) DEFAULT NULL,
`status` varchar(30) DEFAULT NULL,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
)
注意这里service_id和service_area_id分别是两个不同模型services和service_areas的外键。
services.sql
CREATE TABLE `services` (
`id` char(36) NOT NULL,
`title` varchar(45) DEFAULT NULL,
`description` text,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
)
和service_areas.sql
CREATE TABLE `service_areas` (
`id` char(36) NOT NULL,
`postal_id` char(36) DEFAULT NULL,
`area_name` varchar(45) DEFAULT NULL,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `postal_id_idx` (`postal_id`)
)
我有另一个表来维护客户(服务提供商)提供的服务列表。
CREATE TABLE `client_services` (
`id` char(36) NOT NULL COMMENT ' ',
`client_id` char(36) DEFAULT NULL,
`service_id` char(36) DEFAULT NULL,
`charge` float DEFAULT NULL,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `client_id_idx` (`client_id`),
KEY `service_id_idx` (`service_id`)
)
以及另一个用于维护服务提供商所涵盖的服务领域列表的表格。
CREATE TABLE `client_service_areas` (
`id` char(36) NOT NULL,
`client_id` char(36) DEFAULT NULL,
`service_area_id` char(36) DEFAULT NULL,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `client_id_idx` (`client_id`),
KEY `service_area_id_idx` (`service_area_id`)
)
serviceReqest 模型:serviceRequest.php
class ServiceRequest extends AppModel {
public $displayField = 'status';
/**
* belongsTo associations
*
* @var array
*/
public $belongsTo = array(
'Customer' => array(
'className' => 'Customer',
'foreignKey' => 'customer_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'CustomerAddress' => array(
'className' => 'CustomerAddress',
'foreignKey' => 'customer_address_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Service' => array(
'className' => 'Service',
'foreignKey' => 'service_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'ServiceArea' => array(
'className' => 'ServiceArea',
'foreignKey' => 'service_area_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
}
通过访问请求view 操作:
http://localhost/service_requests/view/<service_request_id>
它显示来自 service_requests 的结果
现在我要做的是在此视图下方显示一个列表,其中包含在请求的服务区域中提供请求的服务的客户名称(在同一服务区域中可以有许多服务提供商提供相同的服务)。 em>
这意味着在Ghaziabad中显示为Carpenter提供服务的客户列表
从clients 表中获取客户的名称和其他详细信息。
【问题讨论】:
-
请展示你到目前为止所做的尝试
-
我是 CakePHP 的新手,这是我在学习完博客教程之后的第一个项目,因此,寻找从哪里开始的想法。
-
所以也许 stackoverflow 不是寻求帮助的正确地方,看看 help page 什么被认为是题外话。另外:如果这是你的第一个蛋糕项目,为什么不从 cakephp 3 而不是 cakephp 2 开始?
-
我正在使用 Netbeans IDE,但 CakePHP 3.0 没有官方支持的插件
标签: cakephp multiple-tables cakephp-2.x cakephp-2.7