Welcome Guest, Not a member yet? Register   Sign In
Object of class could not be converted to string
#1

Hi, guys I'm a (beginner) in CI4. Can anyone give me advice about this?
I'm trying to pass my getPost value to model, but it says that
Object of class App\Models\Criteria could not be converted to string

controller:
[size=1]  public function dataFilter(){
        // Get Value on select id CatID
        $criteria = new Criteria();
        $CatID = $this->request->getPost('CatID');
        $details= $this->$criteria->fetchDataFilter($CatID); --------- Object of class App\Models\Criteria could not be converted to string
[/size]

[size=1]
        $data['questions'] = $criteria->fetchDataFilter([size=1][size=1]$CatID
);
     
[/size]        // return response to ajax
        return $this->response->setJSON($data);
    }
[/size]


Model
[/size]

[size=1] public function fetchDataFilter($CatID){
        $CatID = $this->request->getPost('CatID');
        $db  = \Config\Database::connect();
        $builder = $db->table('tblcriteria');
        $builder->select('*');
        $builder->join('tblcriteriadetail', 'tblcriteriadetail.CatID = tblcriteria.CatID');
        $builder->where('tblcriteria.CatID', $CatID);
        $builder->where('tblcriteria.status', 1);

        $result = $builder->get()->getResult();
        return $result;

    }



    }
[/size]
Reply
#2

(This post was last modified: 07-28-2022, 06:06 AM by JustJohnQ.)

Your model returns an object. You try to store this object in the variable $details.
add a line before calling your model:
$details = new stdClass();

Whoops, ignore that. That doesn't make sense. I guess I didn't have enough coffee there.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB