Answer the question
In order to leave comments, you need to log in
How to correctly pass json and get it in the controller?
Pass json array to controller (namesDp)
$http({
method: "POST",
url: "http://localhost/cabinet/contracts/addContract",
data: $.param({
......
namesDp: $scope.data.model
}),
$dpList = json_decode($_POST['namesDp']);
if($this->model->addContract($dpList, $contractNumber,$contractTitle, $contractDate . . . ..
public function addContract( $dpList, $contractNumber,$contractTitle, $contractDate . . . . .. . . ) {
foreach($dpList as $value) {
$sql = "INSERT INTO contract(department, numberContract, nameContract, dateConclusion)
VALUES(:department, :numberContract, :nameContract, :dateConclusion)
";
$stmt = $this->db->prepare($sql);
$stmt->bindValue(":department", $value, PDO::PARAM_INT);
$stmt->bindValue(":numberContract", $contractNumber, PDO::PARAM_INT);
$stmt->bindValue(":nameContract", $contractTitle, PDO::PARAM_STR);
$stmt->bindValue(":dateConclusion", $contractDate, PDO::PARAM_STR);
$stmt->execute();
. . ... .
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question