【发布时间】:2012-02-23 12:20:21
【问题描述】:
我使用 CodeIgniter 构建了一个双语应用程序,现在我需要 2 个 cron 作业来向某些用户发送电子邮件。
我遇到的问题是我无法运行 cron 作业,我相信这是因为我必须以多种语言运行 CodeIgniter。
我正在尝试运行此命令: php /home/[用户名]/public_html/projects/[项目名称]/index.php cron提醒
运行后我收到的电子邮件如下:
Content-type: text/html
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Warning</p>
<p>Message: array_key_exists() [<a href='function.array-key-exists'>function.array-key-exists</a>]: The first argument should be either a string or an integer</p>
<p>Filename: core/MY_Lang.php</p>
<p>Line Number: 153</p>
</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Warning</p>
<p>Message: array_key_exists() [<a href='function.array-key-exists'>function.array-key-exists</a>]: The first argument should be either a string or an integer</p>
<p>Filename: core/MY_Lang.php</p>
<p>Line Number: 153</p>
</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Warning</p>
<p>Message: Cannot modify header information - headers already sent by (output started at /home/vchris/CI-2.0.1/core/Exceptions.php:170)</p>
<p>Filename: core/MY_Lang.php</p>
<p>Line Number: 73</p>
</div>
MY_Lang.php 标题在第 73 行
if ((!$url_ok) && (!$this->is_special($uri_segment['parts'][0]))) // special URI -> no redirect
{
// set default language
$CFG->set_item('language', $this->languages[$this->default_lang()]);
$uri = (!empty($this->uri)) ? $this->uri: $this->default_uri;
$uri = ($uri[0] != '/') ? '/'.$uri : $uri;
$new_url = $CFG->config['base_url'].$this->default_lang().$uri;
header("Location: " . $new_url, TRUE, 302);
exit;
}
MY_Lang.php 返回在第 153 行
// default language: first element of $this->languages
function default_lang()
{
$browser_lang = !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? strtok(strip_tags($_SERVER['HTTP_ACCEPT_LANGUAGE']), ',') : '';
$browser_lang = substr($browser_lang, 0,2);
return (array_key_exists($browser_lang, $this->languages)) ? $browser_lang: 'en';
}
基本上当您浏览我的网站时,如果您没有在 url 中设置语言,它会自动添加 /en/。有没有办法绕过它或在控制器中设置它?我认为 MY_Lang 在控制器之前被调用。所以也许有办法让我不必使用index.php进入CodeIgniter。
【问题讨论】:
标签: php codeigniter cron