CodeIgniter: two model methods in a line cause an internal server error

I am new to CodeIgniter and trying to complete my first project. I have two ajax db-update functions that (for myself) work completely fine.

(because queries as such work, I simplify for the sake of this example :)

    public function updateA($data) {

            $this->pos1    = $data['pos1'];
            $this->pos2    = $data['pos2']; 

            $this->db->where('id', 1);

            $result = $this->db->update('tablePos', $this);
    }

and

    public function updateB($data) {

            foreach ($data as $value) {

                    $this->name    = $value['name'];
                    $this->type    = $value['type']; 
                    $this->db->where('id', $value['ID']);

                    $result = $this->db->update('tableNames', $this);
            }

    }

As already mentioned, both of them work like a charm if I call them in my controller "one . " So that,

$this->MainModel->updateA($data);

OR

$this->MainModel->updateB($data);

but NOT

$this->MainModel->updateA($data);
$this->MainModel->updateB($data);

Then the first request is executed, but not the second. It doesn't matter which one I call first. In case I call both in a line, only the fist is executed and my ajax function returns

Failed to load the resource: the server responded with a status of 500 (Internal server error)

I spend the whole night searching - I don’t know ... :(

EDIT:

:

CONTROLLER:

        public function parse()
    {
            $this->load->model('MainModel');

            $position =  '{"ID":1,"pos1":5,"pos2":6}';
            $position = json_decode($position, true);

            $names =  '[{"ID":1,"name":"AAAA","type":9},{"ID":2,"name":"BBBBB","type":2},{"ID":3,"name":"CC","type":4}]';
            $names = json_decode($names, true);

            $this->MainModel->updateA($position);
            $this->MainModel->updateB($names);
    }

:

        public function updateA($data_a) {
            error_log("----------- start A -----------");
            $this->pos1    = $data_a['pos1'];
            $this->pos2    = $data_a['pos2']; 
            $this->db->where('id', 1);
            $result = $this->db->update('tablePos', $this);
            error_log($this->db->last_query());
            error_log("----------- stop A -----------");
    }


    public function updateB($data_b) {
            error_log("----------- start B -----------");
            foreach ($data_b as $value) {

                    $this->name    = $value['name'];
                    $this->type    = $value['type']; 
                    $this->db->where('id', $value['ID']);

                    $result = $this->db->update('tableNames', $this);
                    error_log($this->db->last_query());
            }
            error_log("----------- stop B -----------");
    }

BOTH :

[03-Dec-2015 14:13:15 /] ----------- A -----------

[03-Dec-2015 14:13:15 /] UPDATE tablePos SET pos1= 5, pos2= 6 WHERE id= 1

[03-Dec-2015 14:13:15 /] ----------- A -----------

[03-Dec-2015 14:13:15 /] ----------- B -----------

    $this->MainModel->updateA($position);
    // $this->MainModel->updateB($names);

[03-Dec-2015 14:23:23 /] ----------- A -----------

[03-Dec-2015 14:23:23 /] UPDATE tablePos SET pos1= 5, pos2= 6 WHERE id= 1

[03-Dec-2015 14:23:23 /] ----------- A -----------

    // $this->MainModel->updateA($position);
    $this->MainModel->updateB($names);

[03-Dec-2015 14:25:14 /] ----------- B -----------

[03-Dec-2015 14:25:14 /] UPDATE tableNames SET name= 'AAAA', type= 9 WHERE id= 1 [03-Dec-2015 14: 25:14 /]

UPDATE tableNames SET name= 'BBBBB', type= 2 WHERE id= 2

[03-Dec-2015 14:25:14 /] UPDATE tableNames SET name= 'CC', type= 4 WHERE id= 3

[03-Dec-2015 14:25:14 /] ----------- B -----------

. . DOES php-, . ...

+4
2

$this :

public function updateA($data_a) {
            error_log("----------- start A -----------");
            $this->db->where('id', 1);
            $updateData = array(
                               'pos1' => $data_a['pos1'],
                               'pos2' =>  $data_a['pos2'],
                           ); 
            $result = $this->db->update('tablePos', $updateData);
            error_log($this->db->last_query());
            error_log("----------- stop A -----------");
    } 

  public function updateB($data_b) {
            error_log("----------- start B -----------");
            foreach ($data_b as $value) {
                  $updateData = array(
                               'name' => $value['name'],
                               'type' =>  $value['type'],
                           ); 
                    $this->db->where('id', $value['ID']);

                    $result = $this->db->update('tableNames',$updateData);
                    error_log($this->db->last_query());
            }
            error_log("----------- stop B -----------");
    }

, , .

$this - , , , .

, , .

+1

Source: https://habr.com/ru/post/1618424/


All Articles