【问题标题】:Codeigniter Cron - "The controller/method pair you requested was not found"Codeigniter Cron - “未找到您请求的控制器/方法对”
【发布时间】:2016-05-07 20:59:12
【问题描述】:

我正在寻求帮助。我在 codeigniter 中有一个应用程序,我正在尝试实现一个 cron 作业来自动化我的控制器中的一个方法,以便每隔一小时左右运行一次......

我在相关页面上有大量代码,但我的错误是“找不到您请求的控制器/方法对”。

Cron 命令(来自终端)是:php index.php cron index

控制器(缩短。我删除了与我的问题无关的其他方法):

include('application/libraries/Twilio.php');
require_once 'application/third_party/Infusionsoft/infusionsoft.php';

class Cron extends CI_Controller{

public $pagination_config;
public $total_rows;
private $users_table_name;
private $review_sites_table_name;
private $ci;
public $customer_reviews_info;

function __construct() {
    parent::__construct();
    $this->ci = & get_instance();
    $this->load->database();
    $this->load->helper('url');
    $this->load->helper(array('form', 'url'));
    $this->load->helper('security');
    $this->load->library('form_validation');
    $this->load->library('pagination');
    $this->load->library('tank_auth');
    $this->lang->load('tank_auth');
    $this->load->model('CronModel');
    $this->load->library('simple_html_dom');
    $this->load->config('twilio', TRUE);

    $this->AccountSid = $this->config->item('account_sid', 'twilio');
    $this->AuthToken = $this->config->item('auth_token', 'twilio');

    $this->users_table_name = $this->ci->config->item('users_table_name', 'tank_auth');
    $this->review_sites_table_name = $this->ci->config->item('review_sites_table_name', 'tank_auth');
    $this->customer_reviews_info = $this->ci->config->item('customer_reviews_info', 'tank_auth');
}

  public function index()
  {
    echo "Hello, World" . PHP_EOL;
  }

}

控制器文件名为 cron.php。如果我在浏览器中运行 url,它可以正常工作。如果我尝试使用终端,我会收到错误消息。我觉得我已经研究了很多并且没有任何运气。我很感激我能得到的任何帮助。我不确定您可能需要哪些其他信息来帮助我,但如果您提出要求,我会为您提供帮助我所需的信息。

【问题讨论】:

  • CI 3+ 版本需要控制器和其他由ucfirst 规则命名的类(例如 Cron.php)。
  • 谢谢。我更改了文件名并解决了该问题。但是,现在我得到“mysqli::real_connect(): (HY000/2002): Connection denied” 我已经尝试了 localhost 和 127.0.0.1 作为主机名,还包括端口 3306,但仍然是同样的错误。对这个新错误有什么帮助吗?
  • 没关系,Tpojka,您的帮助确实解决了我的问题。是我的错误导致连接被拒绝。谢谢!

标签: php codeigniter cron


【解决方案1】:

CI 3+ 版本需要控制器和其他由ucfirst() 规则命名的类(例如Cron.php)。 Docs.

【讨论】:

    猜你喜欢
    • 2017-11-16
    • 2013-10-04
    • 1970-01-01
    • 1970-01-01
    • 2016-10-12
    • 2012-08-18
    • 1970-01-01
    • 2021-11-11
    • 1970-01-01
    相关资源
    最近更新 更多