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