![]() |
Help me to create Models CI4 - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Help me to create Models CI4 (/showthread.php?tid=75416) |
Help me to create Models CI4 - mjamilasfihani - 02-04-2020 Hi, there! I want to create some MyModel inside app/Models directory, I have followed CI4 docs. But I got this error : Code: Too few arguments to function App\Models\MyModel::__construct(), 0 passed in C:\xampp\htdocs\project-name\my.project-name.tld\acme\Home I have tried like this in BaseController (because I am using hmvc) : Code: // Load Database But still got same error, maybe I miss understand? Thanks ![]() RE: Help me to create Models CI4 - InsiteFX - 02-04-2020 Try this one and see if it works for you. PHP Code: class UserModel RE: Help me to create Models CI4 - mjamilasfihani - 02-04-2020 (02-04-2020, 06:02 AM)InsiteFX Wrote: Try this one and see if it works for you. It still not working as well, here the error Code: Class 'App\Models\Database' not found I have tried Code: $this->db = \Database::connect($this->DBGroup); Still not working. I have checked my db config, nothing I miss with that. This script try to connect database in app\Config\Database, isn't? Code: $this->db = Database::connect($this->DBGroup); Here is my full script, after got suggestion from InsiteFX PHP Code: <?php namespace App\Models; RE: Help me to create Models CI4 - InsiteFX - 02-04-2020 Try one of these. PHP Code: $this->db = Database::connect(); A convenience method exists that is purely a wrapper around the above line and is provided for your convenience: PHP Code: $db = db_connect(); RE: Help me to create Models CI4 - mjamilasfihani - 02-04-2020 (02-04-2020, 01:08 PM)InsiteFX Wrote: Try one of these. the helper its working for me, great! |