M
M
Mitrandil2017-01-03 18:31:54
CodeIgniter
Mitrandil, 2017-01-03 18:31:54

Error while outputting strpos() expects parameter 1 to be string, object given?

When outputting values, two errors appear:

Message: strpos() expects parameter 1 to be string, object given Filename: database/DB_active_rec.php

explode() expects parameter 2 to be string, object given Filename: database/DB_active_rec.php

Model:
class Services extends CI_Model
{

private $table = 'services';

public function __construct()
{
    parent::__construct();
}

function get_all(){

    return $this->db->get($this->services)->result();
}

function add($title,$description,$price,$img){
    $data = array(
        'title' => $title,
        'img'   => $img,
        'description'   => $description,
        'price' => $price
    );

    $this->db->insert('services',$data);
}
}

In the controller, because of these two lines, an error appears:
$services = $this->services->get_all();


    $data['services']= $services;

View:
<?php foreach($services as $service):?>

            <?php echo $service->title.'<br/>' ?>

    <?php endforeach?>

In the DB_active_rec.php file, it swears at these lines:
if (strpos($table, ',') !== FALSE)
    {
        return $this->_track_aliases(explode(',', $table));
    }

I don’t understand what exactly needs to be corrected, because everything works, the data is displayed, but there are still errors, tell me what is the reason and how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor, 2017-01-03
@Mitrandil

In the get_all() method, change the table to $this->table

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question