Skip to main content
se eliminaron 617 caracteres en el cuerpo
Origen Enlace
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)));
   
    /*$category = $request->getPost('category');
    $description_rule = $request->getPost('description_rule');
    $name_rule= $request->getPost('name_rule');
    $points_rule= $request->getPost('points_rule');

    $status_insert=$accountModel->add_rule_insert(array(

        "category_partner" => $category,
        "description" => $description_rule,
        "name_rule" => $name_rule,
        "points" => $points_rule,
        "active" => 1,
        "fecha_registro" => $fechaActual,
        "user_id" => $id_user
    ));
    echo $status_insert;*/
}
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)));
   
    /*$category = $request->getPost('category');
    $description_rule = $request->getPost('description_rule');
    $name_rule= $request->getPost('name_rule');
    $points_rule= $request->getPost('points_rule');

    $status_insert=$accountModel->add_rule_insert(array(

        "category_partner" => $category,
        "description" => $description_rule,
        "name_rule" => $name_rule,
        "points" => $points_rule,
        "active" => 1,
        "fecha_registro" => $fechaActual,
        "user_id" => $id_user
    ));
    echo $status_insert;*/
}
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)));
   
    
}
Origen Enlace

¿como puedo recuperar estos datos en el controlador?

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)));
   
    /*$category = $request->getPost('category');
    $description_rule = $request->getPost('description_rule');
    $name_rule= $request->getPost('name_rule');
    $points_rule= $request->getPost('points_rule');

    $status_insert=$accountModel->add_rule_insert(array(

        "category_partner" => $category,
        "description" => $description_rule,
        "name_rule" => $name_rule,
        "points" => $points_rule,
        "active" => 1,
        "fecha_registro" => $fechaActual,
        "user_id" => $id_user
    ));
    echo $status_insert;*/
}