当我阻止多个评论时,该问题是多个的,它不起作用。 如果我阻止单个评论,则它可以完全正常工作。 请阅读我的HTML和PHP代码,并告诉我该问题的解决方案。
复选框的HTML代码
<input class="allCheck" type="checkbox" name="check12[]" value="<?php
echo $d['ID']; ?>" />
PHP控制器: 这是定义dataAccess的两种方法
public function multipleBlockAction() {
$request = $this->request;
$arrdatas = array();
$commentsValues = $request->getPost("check12");
$sizeOfvalue = sizeof($commentsValues) - 1;
for ($x = 0; $x <= $sizeOfvalue; $x++) {
$checkOneByOne = $commentsValues[$x];
$commentdata = $this->_commentservice->getCommentById($checkOneByOne);
foreach ($commentdata as $ucdata) {
$arrdatas = $ucdata->toArray();
$arrdatas['Status'] = '2';
$arrdatas['Block_DateTime'] = date('Y-m-d H:i:s');
$result = $this->_commentservice->totrashcomment($arrdatas);
if (is_object($result)) {
$result = $result->getMessages();
$this->logErrorMessage($result);
foreach ($result as $res) {
$this->flash->error($res);
}
} else {
$this->flashSession->success('<div class="alert alert-success text-center">Comment is Blocked successfully</div>');
$previous = $this->session->get('previous_url');
return $this->response->redirect($previous);
}
}
}
}
getCommentById :我已经提到了此方法,它正在调用控制器。
public function getCommentById($comid) {
try {
$transaction = $this->_transaction->get();
$this->_userComment->setTransaction($transaction);
$result = $this->_userComment->find("ID = '{$comid}'");
return $result;
} catch (TxFailed $e) {
return $this->_userComment;
}
}
totrashcomment :此方法也在调用控制器
public function totrashcomment($data) {
//print_r();
try {
$transaction = $this->_transaction->get();
$this->_userComment->setTransaction($transaction);
$conditions = "Unique_ID = {$data['Unique_ID']} and MainComment = '1'";
$data1 = $this->_userComment->find(array($conditions))->toArray();
if (count($data1) > 0) {
return;
} else {
if ($this->_userComment->save($data) == false) {
$transaction->rollback('comment not updated');
}
}
//Everything goes fine, let's commit the transaction
$transaction->commit();
} catch (TxFailed $e) {
return $this->_userComment;
}
}