我的Slim - Rest - API遇到了问题,唯一剩下的就是我头上的问号。
我已经在我的API中加入了几个表,这些表工作正常:
// Detail View of Task
$app->get('/task_detail/:id', function($id) use ($app, $db) {
$task_data_array = array();
foreach ($db->task()->where('task_id', $id) as $task) {
$task_data_array[] = array(
'task_id' => $task['task_id'],
'task_date' => $task['task_date'],
'task_deadline' => $task['task_deadline'],
'target_snr' => $task['target_snr'],
'client_name' => $task->client['client_name'],
'client_adress' => $task->client['client_adress'],
'client_zip' => $task->client['client_zip'],
'client_contact' => $task->client['client_contact'],
'workflow_id' => $task['workflow_id'],
'task_type' => $task->task_type['task_type'],
'task_desc' => $task->task_type['task_desc'],
'status' => $task['status']
);
}
$app->response()->header('Content-Type', 'application/json;charset=utf-8');
echo json_encode($task_data_array);
});
返回:
[{"task_id":"1","task_date":"2016-06-15","task_deadline":"2016-06-30 11:00:00.000000","target_snr":"12523452343","client_name":"Stahlbau AG","client_adress":"Stahlbruch 40","client_zip":"48881","client_contact":"stahl@stahlbauag.de","workflow_id":"1","task_type":"blabla","task_desc":"blabla","status":"Open"}]
在这里,我将我的任务表与client和task_type表连接起来。它工作正常。
BUT:
现在我得到了两个连接不起作用的示例,只返回“null”作为连接值:
代码:
// Workflow for Detail
$app->get('/workflow_detail/:id', function($id) use ($app, $db) {
$workflow_data_array = array();
foreach ($db->workflow()->where('workflow_id', $id) as $workflow_detail) {
$workflow_data_array[] = array(
'workflow_id' => $workflow_detail['workflow_id'],
'workflow_name' => $workflow_detail['workflow_name'],
'workflow_desc' => $workflow_detail['workflow_desc'],
'product_id' => $workflow_detail->product['product_id'],
'product_type' => $workflow_detail->product['product_type'],
'product_name' => $workflow_detail->product['product_name'],
'list_category_id' => $workflow_detail->list_category['list_category_id'],
'list_category_desc' => $workflow_detail->list_category['list_category_desc']
);
$app->response()->header('Content-Type', 'application/json;charset=utf-8');
echo json_encode($workflow_data_array);
}
});
返回:
[{"workflow_id":"2","workflow_name":"Reparatur","workflow_desc":"blabla","product_id":"2","product_type":null,"product_name":null,"list_category_id":"1004","list_category_desc":"Hardware-Tausch"}]
我在另一个问题上遇到同样的问题:
$app->get('/task_solution/:id', function($id) use ($app, $db) {
$solution_array = array();
foreach ($db->task_list_solution()->where('task_id',$id) as $solution) {
$solution_array[] = array(
'task_id' => $solution['task_id'],
'list_catalog_id' => $solution['list_catalog_id'],
'list_catalog_task' => $solution->list_catalog['list_catalog_task'],
'list_catalog_desc' => $solution->list_catalog['list_catalog_desc'],
'task_date' => $solution->task['task_date'],
'target_snr' => $solution->task['target_snr']
);
$app->response()->header('Content-Type', 'application/json;charset=utf-8');
echo json_encode($solution_array);
}
});
返回:
[{"task_id":"1","list_catalog_id":"11","list_catalog_task":"Akku Aufschrauben","list_catalog_desc":"Akkufach aufschrauben. Dafuer 13 Schrauben entfernen blabla","task_date":null,"target_snr":null}]
我已经尝试了一些东西,但似乎没有任何效果。我不明白为什么它在一个部分工作而不是这个部分..
这是我的NOTORM结构和使用的表结构:
$structure = new NotORM_Structure_Discovery($pdo, $cache = null, $foreign = '%s_id');
工作流程表:
-- -----------------------------------------------------
-- Table `itec_app_workflow`.`workflow`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `itec_app_workflow`.`workflow` (
`workflow_id` INT NOT NULL AUTO_INCREMENT,
`workflow_name` VARCHAR(100) NULL,
`workflow_desc` VARCHAR(150) NULL,
`workflow_adv_desc` VARCHAR(150) NULL,
`product_id` INT NOT NULL,
`list_category_id` INT NOT NULL,
PRIMARY KEY (`workflow_id`, `product_id`, `checklist_category_id`),
INDEX `fk_workflow_produkt1_idx` (`product_id` ASC),
INDEX `fk_workflow_checklist1_idx` (`list_category_id` ASC),
CONSTRAINT `fk_workflow_produkt1`
FOREIGN KEY (`product_id`)
REFERENCES `itec_app_workflow`.`product` (`product_id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_workflow_checklist1`
FOREIGN KEY (`list_category_id`)
REFERENCES `itec_app_workflow`.`list_category` (`list_category_id`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;
产品表:
-- -----------------------------------------------------
-- Table `itec_app_workflow`.`product`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `itec_app_workflow`.`product` (
`product_id` INT NOT NULL AUTO_INCREMENT,
`product_name` VARCHAR(100) NULL,
`product_type` VARCHAR(45) NULL,
`manu_id` INT NOT NULL,
PRIMARY KEY (`product_id`, `manu_id`),
INDEX `fk_produkt_hersteller1_idx` (`manu_id` ASC),
CONSTRAINT `fk_produkt_hersteller1`
FOREIGN KEY (`manu_id`)
REFERENCES `itec_app_workflow`.`manufacturer` (`manu_id`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;
Task_list_solution,list_catalog和task:
-- -----------------------------------------------------
-- Table `itec_app_workflow`.`task`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `itec_app_workflow`.`task` (
`task_id` INT NOT NULL AUTO_INCREMENT,
`task_date` DATE NULL,
`task_deadline` DATETIME(6) NULL,
`target_snr` VARCHAR(45) NULL,
`client_id` INT NOT NULL,
`tech_id` INT NOT NULL,
`workflow_id` INT NOT NULL,
`task_type_id` INT NOT NULL,
PRIMARY KEY (`task_id`, `client_id`, `tech_id`, `workflow_id`, `task_type_id`),
INDEX `fk_auftrag_kunden1_idx` (`client_id` ASC),
INDEX `fk_auftrag_techniker1_idx` (`tech_id` ASC),
INDEX `fk_auftrag_workflow1_idx` (`workflow_id` ASC),
INDEX `fk_auftrag_auftrags_typ1_idx` (`task_type_id` ASC),
CONSTRAINT `fk_auftrag_kunden1`
FOREIGN KEY (`client_id`)
REFERENCES `itec_app_workflow`.`client` (`client_id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_auftrag_techniker1`
FOREIGN KEY (`tech_id`)
REFERENCES `itec_app_workflow`.`tech` (`tech_id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_auftrag_workflow1`
FOREIGN KEY (`workflow_id`)
REFERENCES `itec_app_workflow`.`workflow` (`workflow_id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_auftrag_auftrags_typ1`
FOREIGN KEY (`task_type_id`)
REFERENCES `itec_app_workflow`.`task_type` (`type_id`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `itec_app_workflow`.`list_catalog`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `itec_app_workflow`.`list_catalog` (
`list_catalog_id` INT NOT NULL AUTO_INCREMENT,
`list_catalog_task` VARCHAR(150) NULL,
`list_catalog_desc` VARCHAR(150) NULL,
PRIMARY KEY (`list_catalog_id`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `itec_app_workflow`.`task_list_solution`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `itec_app_workflow`.`task_list_solution` (
`task_list_solution_id` INT NOT NULL AUTO_INCREMENT,
`task_list_solution_answer` TINYINT(1) NULL,
`list_catalog_id` INT NOT NULL,
`task_id` INT NOT NULL,
PRIMARY KEY (`task_list_solution_id`, `list_catalog_id`, `task_id`),
INDEX `fk_auftr_checklist_solution_check_katalog1_idx` (`list_catalog_id` ASC),
INDEX `fk_auftr_checklist_solution_auftrag1_idx` (`task_id` ASC),
CONSTRAINT `fk_auftr_checklist_solution_check_katalog1`
FOREIGN KEY (`list_catalog_id`)
REFERENCES `itec_app_workflow`.`list_catalog` (`list_catalog_id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_auftr_checklist_solution_auftrag1`
FOREIGN KEY (`task_id`)
REFERENCES `itec_app_workflow`.`task` (`task_id`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;
我真的希望你们能帮助我。
顺便说一句:加入PHPMYADMIN工作正常(没有null)它的NOTORM,但我不明白为什么。