I
I
Ilya Trusov2015-12-09 07:02:15
CodeIgniter
Ilya Trusov, 2015-12-09 07:02:15

How to fix Call to a member function result() on a non-object in?

Good day.
I am using codeigniter framework in php. This is the situation:
In the controller:

$data_app = array(
      'key_api' => substr(md5(uniqid(rand(), true)), 0, 22)
    );
    
    $data['app'] = $data_app;
    $this->load->view('apps/new', $data);

In display:
<?php foreach ($app->result() as $data): ?>
<?= $data->key_api; ?>
<?php endforeach; ?>

*Yeah, tagging mess, I know, just for example*
Fatal error: Call to a member function result() on a non-object in.
I don't understand, because we created an array. And the result() method converts it to an array of objects. Why error?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Mokhov, 2015-12-09
@artgrosvil

$app is an array, not an object! where does it get the result() method from?
This is exactly what the error tells you that you are trying to call the result () method from a non-object.

K
krypt3r, 2015-12-09
@krypt3r

result() operates on data retrieved from the database. You wrote nonsense here. You created an array, and work with the variable as an array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question