I'm making a Cron job in CodeIgniter and I need access to my models in order to perform it's tasks. Here's my controller code.
<?php
/**
*
*/
class Cron extends CI_Controller
{
function __construct() {
if ( PHP_SAPI !== 'cli' ) exit('No web access allowed');
}
public function send_mail() {
$this->load->model("mail_model");
foreach ($this->mail_model->cron_job() as $mail) {
echo $mail->id;
}
}
}
If I call the send_mail function using CLI using this command:
php /home/path/to/project/index.php cron send_mail
It returns this error:
Message: Undefined property: Cron::$load
PHP Fatal error: Call to a member function model() on null in /home/path/to/project/application/controllers/cron.php on line 12
If I var_dump($this)
it returns an empty object so I'm confused because it's extending CI_Controller
.
Any ideas?