CodeIgniter任务调度器,将函数传递给任务调度器


CodeIgniter task scheduler taking the function to the task scheduler

我是CRON工作的新手,所以我正在练习它;对于初学者,我正在做一个CRON工作,添加一个用户与CodeIgniter和PHP,这是我的模型:

    <?php 
    class Cron_Model extends CI_Model{
    public function adduser($firstname,$lastname){
    $data = array(
        'firstname' => $firstname,
        'lastname' => $lastname
        );
    $query = $this->db->insert('user_account',$data);
    return $query;
       }
    }

AND:这是我的控制器:

    <?php
    class Cron_Controller extends CI_Controller{
    public function __construct(){
    parent::__construct();
    $this->load->database();
    $this->load->model('Cron_Model');
    // this controller can only be called from the command line
    if (!$this->input->is_cli_request()) show_error('Direct access is not allowed');
}
public function AddAUser(){
    $fname = "JUNCEL";
    $lname = "CARREON";
    $this->Cron_Model->adduser($fname,$lname);
}
}
  ?>

我要把这个添加到数据库中,即使名字和姓氏是相同的,这只是一个试验工作。

所以现在我试图调用函数AddAUser()到任务调度程序,

我试过这个东西:在任务调度程序上浏览它

  C:'xampp'htdocs'post'application'controllers'cron_controller.php
然后在添加参数(可选):我放入AddAUser,所以基本上它变成这样:
 C:'xampp'htdocs'post'application'controllers'cron_controller.php AddAUser

然后我试着运行它,但我没有在数据库中看到任何东西!发生了什么?

像这样更改模型:

<?php 
class cronjob extends CI_Model{
public function __construct()
{
    //load and config db
    $this->load->database();
    parent::__construct();
}
public function adduser($firstname,$lastname){
$data = array(
    'firstname' => $firstname,
    'lastname' => $lastname
    );
$query = $this->db->insert('user_account',$data);
return $query;
   }
}

将控制器更改为:

  <?php
    //Change It to `class Cron extends...` maybe your Prefixes have conflict
    class Cron_Controller extends CI_Controller{
    public function __construct(){
    parent::__construct();

    // this controller can only be called from the command line
    if (!$this->input->is_cli_request()) show_error('Direct access is not allowed');
}
public function AddAUser(){
    //Database Load is accable just in a Model Class
    $this->load->model('cronjob');
    $fname = "JUNCEL";
    $lname = "CARREON";
    $this->cronjob->adduser($fname,$lname);
}
}

数据库加载器在错误的位置,前缀可能有冲突。