How to write query on Model and Call Model using Controller in Codeigniter 4? |
I am trying to fetch values from users table but throws error. Can anyone give sample snippet for the query (Select, Insert)?
PHP Code: <?php namespace App\Models; Please point out what I am doing wrong with the above code
You don't need to write the SQL query. Use findAll like this:
PHP Code: public function all() See the this example: https://codeigniter4.github.io/userguide...your-model Like in CI3, you can return the data as an object or as an array. In CI4 use asArray or asObject: https://codeigniter4.github.io/userguide...pe-changes
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
public function all()
{ return $this->asArray()->findAll(); } this code not working in ci4 please suggest me how to select table data in ci4
Guys I found way to pass/fetch values between controller and model with hints you provided.
Let me share the sample CRUD system once it is done. Thanks Guys |
Welcome Guest, Not a member yet? Register Sign In |