我想從控制器傳遞foreach值來查看,但我只收到一個空數組。在下面的代碼基於foreach中的值我執行了一個查詢,我想設置值,以便我可以在視圖中使用它。從控制器傳遞foreach的值來查看
foreach($logresponse as $row1){
$customerid = $row1['customerid'];
$topicid = $row1['topicid'];
$todolistid = $row1['todolistid'];
$sqlQry="select leadid,customerid as leadcustid,formname from lead_frontend where customerid='$customerid' order by leadid DESC limit 1";
$leadInfo[] = $this->execute_flatten($sqlQry);
if($topicid == 1){
$query2="SELECT a.*,b.username,b.user_id,b.group_id,b.email as salesmanemail,d.email,d.phone1,e.subject,e.subject1,e.content,e.embed_template FROM todolist_frontend as a LEFT JOIN users_backend as b ON a.salesmanid=b.user_id LEFT JOIN customer as c ON c.customerid=a.customerid LEFT JOIN customer_address as d ON d.customerid=a.customerid LEFT JOIN admin_email_action as e ON a.combination_id=e.combination_id where a.todolistid='$todolistid'";
}
else if($topicid == 2){
$query2="SELECT a.*,b.username,b.user_id,b.group_id,b.email as salesmanemail,d.email,d.phone1,e.subject,e.subject1,e.call_info as content FROM todolist_frontend as a INNER JOIN users_backend as b ON a.salesmanid=b.user_id INNER JOIN customer as c ON c.customerid=a.customerid INNER JOIN customer_address as d ON d.customerid=a.customerid INNER JOIN admin_call_action as e ON a.combination_id=e.combination_id where a.todolistid='$todolistid'";
}
else if($topicid == 18){
$query2="SELECT a.*,b.username,b.user_id,b.group_id,b.email as salesmanemail,d.email,d.phone1,e.subject,e.subject1,e.call_info as content FROM todolist_frontend as a INNER JOIN users_backend as b ON a.salesmanid=b.user_id INNER JOIN customer as c ON c.customerid=a.customerid INNER JOIN customer_address as d ON d.customerid=a.customerid INNER JOIN admin_managercall_action as e ON a.combination_id=e.combination_id where a.todolistid='$todolistid'";
}
else{
$query2="SELECT a.*,b.username,b.user_id,b.group_id,b.email as salesmanemail,d.email,d.phone1,e.content,e.subject1,f.emailname as subject,g.mailername AS mailersubject FROM todolist_frontend as a LEFT JOIN users_backend as b ON a.salesmanid=b.user_id LEFT JOIN customer as c ON c.customerid=a.customerid LEFT JOIN customer_address as d ON d.customerid=a.customerid LEFT JOIN admin_mailer_action as e ON a.combination_id=e.combination_id LEFT JOIN emailtype_backend as f ON e.subject=f.emailid LEFT JOIN mailer_backend AS g ON e.subject = g.mailerid where a.todolistid='$todolistid'";
}
$result = $this->execute_flatten($query2);
$subjecttodo = array();
foreach ($result as $res1){
if($res1['topicid'] == 1 && !empty($res1['subject'])){
$subject1 = $res1['subject'];
$sub_qry="select emailname from emailtype_backend where emailid=$subject1";
$subject_result=$this->execute_flatten($sub_qry);
$subjecttodo=isset($subject_result['0']['emailname']) ? $subject_result['0']['emailname'] : "";
}
if($res1['topicid'] == 2 || $res1['topicid'] == 18){
$subjecttodo=$res1['subject'];
}
if($res1['topicid'] == 8){
$subjecttodo=$res1['mailersubject'];
}
$this->set('subjecttodo', $subjecttodo);
}
$this->set('leadInfo', $leadInfo);
}
你似乎在你的控制器代碼中有大量的sql - 這不是一件好事(爲什麼有SQL呢,也有點奇怪,因爲查詢很簡單)。至少,所有的邏輯都應該在控制器所調用的模型方法中。 – AD7six
是的你是對的。現在我正在處理邏輯。後來我需要將所有這些簡單代碼更改爲cakePHP格式。無論如何謝謝你的建議。 – Surya