Codeigniter 和 Cron Bootstrapper 的问题
我正在尝试创建一个 cron 作业,同时利用我当前的 CI 设置以及控制器和模型的使用。我使用 Cron Bootstrapper (http://codeigniter.com/wiki/Cron_job_bootstrapper/),因为它使我可以轻松地按需在本地测试进程,或者作为服务器上的传统 cron 进程使用。我可以使用引导程序文件和命令行访问控制器,但是,根据我设置控制器的方式,我收到许多不同的错误消息或警报。
如果我使用 parent::Controller();
保持控制器应有的样子,我会收到以下消息:
无法使用提供的设置连接到您的数据库服务器。
该错误来自 DB_driver.php initialize()
方法。
如果我从控制器中删除对 parent::Controller()
的调用,则会收到以下警报:
<p>Severity: Warning</p>
<p>Message: date(): It is not safe to rely on the system's timezone settings. You
are *required* to use the date.timezone setting or the
date_default_timezone_set() function. In case you used any of those
methods and you are still getting this warning, you most likely misspelled
the timezone identifier. We selected 'America/New_York' for
'EDT/-4.0/DST' instead</p>
<p>Filename: htdocs/cron.php</p>
<p>Line Number: 122</p>`
通过删除 parent::Controller();
我无法通过 $this->load->model('model');
访问任何模型,我收到以下消息:
致命错误:在第 9 行 /Applications/MAMP/htdocs/my_site/system/application/controllers/cron.php 中的非对象上调用成员函数 model()
允许我使用引导程序文件的任何信息CI 将会非常有帮助。
I am trying to create a cron job while taking advantage of my current CI setup and the use of Controllers and Models. I am using Cron Bootstrapper (http://codeigniter.com/wiki/Cron_job_bootstrapper/) because it gives me easy access to test the process locally on-demand or be available as a traditional cron process on a server. I can reach the controller using the bootstrapper file and the command line, however, I am getting many different error messages or alerts depending on how I set up my controller.
If I keep the controller as it should be with parent::Controller();
, I get the following message:
Unable to connect to your database server using the provided settings.
The error is coming from the DB_driver.php initialize()
method.
If I remove the call to parent::Controller()
from the controller then I get the following alert:
<p>Severity: Warning</p>
<p>Message: date(): It is not safe to rely on the system's timezone settings. You
are *required* to use the date.timezone setting or the
date_default_timezone_set() function. In case you used any of those
methods and you are still getting this warning, you most likely misspelled
the timezone identifier. We selected 'America/New_York' for
'EDT/-4.0/DST' instead</p>
<p>Filename: htdocs/cron.php</p>
<p>Line Number: 122</p>`
By removing the parent::Controller();
I am not able to access any models via $this->load->model('model');
and I get the following message:
Fatal error: Call to a member function model() on a non-object in /Applications/MAMP/htdocs/my_site/system/application/controllers/cron.php on line 9
Any info that will allow me to use the bootstrapper file with CI will be very helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在数据库配置文件中设置 $db['default']['db_debug'] = TRUE; 以启用更详细的错误报告。
您需要注意时区警告并在 php.ini 文件中设置默认值。这是自 PHP 5.3 起的新要求。如果您在共享服务器上运行并且无权访问 php.ini,您可以请求您的 Web 主机设置默认值,或者您可以尝试使用引导程序文件顶部的 ini_set() 手动设置它。
检查并查看您的数据库配置文件是否正在加载,如果是,请仔细检查您的数据库连接设置。如果设置正确,则可能有防火墙阻止您,或者您正在连接的数据库用户可能无权访问您尝试使用的数据库。
Set $db['default']['db_debug'] = TRUE; in your database config file to enable more verbose error reporting.
You need to heed the timezone warning and set a default in your php.ini file. This is a new requirement as of PHP 5.3. If you are running on a shared server and do not have access to php.ini, you can either request that your web host set a default value, or you can try setting it manually using ini_set() at the top of your bootstrap file.
Check and see if your database config file is being loaded, and if so, double-check your database connection settings. If the settings are right, there could be a firewall blocking you, or the database user you are connecting with might not have permission to access the database you are trying to use.