我是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;
}
}和:这是我的控制器:
<?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然后在Add arguments(可选):我将AddAUser放入,所以基本上是这样的:
C:\xampp\htdocs\post\application\controllers\cron_controller.php AddAUser然后我试着运行它,但我没有在数据库中看到任何东西!这是怎么回事?
发布于 2016-09-17 16:53:11
按如下代码更改您的模型:
<?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);
}
}数据库加载器的位置错误,前缀可能有冲突。
https://stackoverflow.com/questions/39544754
复制相似问题