PHP Snippet 1:
UIkit.util.on(".uk-sortable", "stop", function (item) {
let ids = "";
$(".uk-sortable tr").each(function () {
id = $(this).data("id");
if (ids == "") {
ids = id;
} else {
ids = ids + ", " + id;
}
});
$.ajax({
url: "/admin/cost/list-update/",
type: "GET",
dataType: "json",
data: {
ids: "" + ids,
},
timeout: 10000,
})
.done(function (result) {
UIkit.notification(`?????????????????`, "success");
})
.fail(function (XMLHttpRequest, textStatus, errorThrown) {
console.log(textStatus);
console.log(errorThrown);
});
});
PHP Snippet 2:
public function listUpdate()
{
$now = Chronos::now();
try {
$this->loadModel('Specs');
if ($this->request->is('ajax')) {
$ids = $this->request->getQuery('ids');
$arr = explode(',', $ids);
for ($i = 1; $i <= count($arr); $i ++) {
$spec = $this->Specs->find();
$connection = ConnectionManager::get('default');
$connection->begin();
$spec->where([
'Specs.spec_id' => $arr[$i - 1],
]);
$sp = array(
'sort' => $i
);
$data = $spec->first();
$data['updated_at'] = $now;
$data['updated_by'] = $this->loginUserInfo['admin_id'];
$this->Specs->patchEntity($data, $sp);
$this->Specs->saveOrFail($data);
$connection->commit();
}
}
$status = true;
$response = $this->response;
$response = $response->withType('application/json');
$response = $response->withStringBody(json_encode(compact('status')));
return $response;
} catch (Exception $e) {
$connection->rollback();
throw $e;
}
}