Welcome Guest, Not a member yet? Register   Sign In
Codeigniter 4 array the null key is not passed
#1

I installed the version of Codeigniter 4 and PHP 7.4.


Code:
composer
"name": "codeigniter4/appstarter"
"require": "codeigniter4/framework": "^4"


I have a problem when returning an array after a query from a model, I don't get null values.

My controller

PHP Code:
$data["data1"] = $this->model->MO_model->Myget($id); 


My model: MO_model


PHP Code:
$query $this->db->query($query_DB);
$results $query->getResultArray();
return 
$results


It happens that $results has all the values of the query.

Ex: in model first the return command
PHP Code:
$results one => "1",two => Null 


When I read the array from the controller immediately after the call to the model.

PHP Code:
Ex$data["data1"] = one => "1" 


The null key is not passed.

I don't know if it's a return behavior of PHP or Codeigniter.

I'm not very experienced and I don't know if it's a Codeigniter or PHP settings problem.

Thanks!
Reply
#2

I tried your code and it is working just fine, the null value got displayed in my controller as in my model.
my php version is still 7.3.1
but I just install CI 4 so it is the latest 4.0.3
Did your code just that or did you use some library or anything else?

Code:
\app\Models\UserAuth.php:23:
array (size=1)
  0 =>
    array (size=13)
      'id_user' => string '1' (length=1)
      'email' => string '[email protected]' (length=13)
      'phone' => null
      'name' => null
      'last_login' => string '2020-06-24 02:18:37' (length=19)
      'last_ip' => string '::1' (length=3)
      'deleted' => string '0' (length=1)

\app\Controllers\Admin\Admin.php:13:
array (size=1)
  0 =>
    array (size=13)
      'id_user' => string '1' (length=1)
      'email' => string '[email protected]' (length=13)
      'phone' => null
      'name' => null
      'last_login' => string '2020-06-24 02:18:37' (length=19)
      'last_ip' => string '::1' (length=3)
      'deleted' => string '0' (length=1)
Reply
#3

Quote:it is as I have shown.
In fact it is very strange.
The only thing I have done is to install dreamwever to try it out.
Then I messed up the public folder and went back to NetBeans.
I try to download the new version of Codeigniter and reconfigure the project.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB