Welcome Guest, Not a member yet? Register   Sign In
Model return Undefined variable: table

I get ErrorException
Undefined variable: table
APPPATH/Models/OptionsModel.php at line 22

22: $option_value = $table->find($item);

<?php namespace App\Models;

use CodeIgniter\Model;

class OptionsModel extends Model
    protected $DBGroup = 'default';
    protected $table = 'options';
    protected $primaryKey = 'option_name';
    protected $returnType = 'array';

    public function get_options($item, $display = 0)
        $option_value = $table->find($item);

        if (empty($option_value)) {
            if (!$display) {
                return $option_value;
            } else {
                echo $option_value;


Any help will be appreciated. Thanks!

Two problems immediately apparent with your code:
1) $table is a class property, yet you access it as $table, when perhaps it should be $this->table
2) $table is a string, and will not have any object access ($table->anything.....)

If using CI's model, you would use the Model class' find method, eg. $this->find($item).
The CI model treats the $table property as the name of a database table the model is bound to.

Theme © iAndrew 2016 - Forum software by © MyBB