Welcome Guest, Not a member yet? Register   Sign In
Why the $this->find( $id ) is generating error but get()->getRow() is working?
#1
Question 

In my model, I am trying to get an item by its ID. My code is given bellow:


PHP Code:
// namespace App\Models;
// use CodeIgniter\Model;

public function getItemByID$cid ){
    return $this->find($cid);


The above code generating the following error:

Code:
TypeError
Argument 1 passed to CodeIgniter\Database\BaseResult::getFirstRow() must be of the type string, null given, called in C:\Users\RON\OneDrive\Dev\oneb\core\Model.php on line 375

But the following code is working fine:

PHP Code:
public function getItemByID$cid ){
    return $this->where([$this->primaryKey => $cid])->get()->getRow();


What is the reason behind this?

Thanks in advance.
"Who thinks in code"
Perfectly describes who I am
mbparvez.me
Reply


Messages In This Thread
Why the $this->find( $id ) is generating error but get()->getRow() is working? - by webdevron - 01-31-2020, 12:57 PM



Theme © iAndrew 2016 - Forum software by © MyBB