Estoy usando codeigniter 4 y quiero recorger estos datos que mande por ajax al controlador
esto me imprime pinrt_r()
[post] => Array (
[datastring] => date_invoice=2022-11-24&number_invoice=65654654&productos=04&amount=2
[select_product_array] => Array ( [0] => 04 [1] => 07 [2] => 10 ) [amount_create_array] => Array ( [0] => 5 [1] => 2 [2] => 2 ) ) ) )
este es mi ajax
$.ajax({
type: "POST",
url: "insert_invoice",
data: {
datastring: datastring,
select_product_array: select_product_array,
amount_create_array: amount_create_array
},
dataType: "json",
success: function(data) {
console.log(data);
//var obj = jQuery.parseJSON(data); if the dataType is not specified as json uncomment this
// do what ever you want with the server response
},
error: function() {
alert('error handling here');
}
});
controller
public function insert_invoice(){
$session = session();
$id_user = $session->get('user_id');
$fechaActual = date('d-m-Y H:i:s');
$accountModel = new AccountModel();
$request = \Config\Services::request();
print_r($request);
//var_dump($request->getPost(json_decode($datastring)));
}
$request['post']['datastring']
o$request['post']['select_product_array']
o$request['post']['amount_create_array']
para acceder a esos datos? Segun elprint_r
el$request
es un simple array que contiene una clave denominadapost
que a su vez contiene otro array con esas tres claves... ¿o no estoy entendiendo lo que quieres hacer ahora tampoco?