How to call models outside CodeIgniter controller? |
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?
How do you run the ExportAlert.php?
If you run it in CLI, CI4 provides Spark commands. https://codeigniter4.github.io/CodeIgnit...mands.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. |
Welcome Guest, Not a member yet? Register Sign In |