How to call models outside CodeIgniter controller? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: How to call models outside CodeIgniter controller? (/showthread.php?tid=87167) |
How to call models outside CodeIgniter controller? - KeroniMasingolir - 03-22-2023 I require assistance with CodeIgniter 4. I have a file named ExportAlert.php in the root directory with the following path: TestingWebsite\app\CronJob\ExportAlert.php. This file is not in the controller. Inside the ExportAlert.php, I am trying to call models using the following code: $Utility = new \App\Models\Dennis_utility_model(); // Class Not Found Error $Setting = new \App\Models\Dennis_setting_model(); // Class Not Found Error $Medoo = new \App\Models\Dennis_medoo_model(); // Class Not Found Error $Telegram = new \App\Models\Dennis_telegram_model(); // Class Not Found Error However, I am receiving a "Class Not Found" error for every model I called. I do not want to put the models inside the controller because I want to run a scheduled task using a cron job and prevent unauthorized users from running it from the browser and spamming it. Is it possible to call a model or class from outside the controller using a custom directory in CodeIgniter 4? In the ExportAlert.php file, I did not use the class, just a native PHP with the model. What is the correct way to call it in CodeIgniter 4? RE: How to call models outside CodeIgniter controller? - kenjis - 03-22-2023 How do you run the ExportAlert.php? If you run it in CLI, CI4 provides Spark commands. https://codeigniter4.github.io/CodeIgniter4/cli/cli_commands.html If you just run like php /path/to/ExportAlert.php, you do not use CI4. In such a case, you need to load or autoload all classes by yourself. |