2016-09-17 7 views
0

私はCRONジョブで新しく、練習しています。スターターのために、私はCodeIgniterのとPHPを持つユーザーを追加するcronジョブを作っています、 はここに私のモデルである:CodeIgniterタスクスケジューラがタスクスケジューラに機能を移す

<?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 

その後、私はそれを実行してみたが、私は、データベースに何かを見ていません!何が起こっている?

答えて

0
は、このコードのように、あなたのモデルを変更

<?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); 
} 

} 

データベースローダーが間違った場所にあり、プレフィックスが競合しているかもしれません。

+0

Codeigniterは古いフレームワークです! 、新しいフレームワークを使用してください 'Yii'、' Phalconphp'、 'laravel'、または小さなプロジェクトのための他のマイクロフレームワーク –

+0

まあまあ!私は私たちの論文の後にlaravelを練習するだろうが、私は何を求めようとしているのかは分からない。何をURL – GGsThePlayDude

+0

ここにあなたのエラーコードを入れて確認してください!このコードは私のすべてのプロジェクトでうまく動作し、 'if(!$ this-> input-> is_cli_request())'を削除し、ブラウザでテストします –

関連する問題