未定义的索引...现有索引? [英] Undefined Index for ... existing index?
问题描述
好,那不只是奇怪的了...
OK, that's more than weird...
这是我的代码:
public function results($id,$pattern=3)
{
$this->load->library('session');
if (!$this->session->userdata('logged_in'))
{
$this->session->set_flashdata('return_url',$this->uri->uri_string());
redirect('log/in','refresh');
}
else
{
$this->load->model('projects');
$proj = (array)$this->projects->getProjectById($id);
print_r($proj);
$progressPercentage = number_format((float)( ($proj['progress'] * 100) / $proj['total'] ), 2, '.', '');
}
}
现在,这是问题所在:
- 将NO
$pattern
传递给控制器时,整个程序运行正常. -
当我传递诸如
mysite.com/project/results/45/4
(pattern = 4)之类的参数时,出现以下错误:
- When NO
$pattern
is passed to the controller, the whole thing works fine. When I pass some parameter, like
mysite.com/project/results/45/4
(pattern=4), I'm getting the following error :
A PHP Error was encountered
Severity: Notice
Message: Undefined index: progress
Filename: controllers/project.php
Line Number: 75
奇怪的是,$id
和$pattern
都可以读取".
The weird thing is that both $id
and $pattern
are "read" fine.
当我在有关undefined index
的行之前print_r
ing $proj
时,我得到的结果是:
When I'm print_r
ing $proj
just before the line concerning undefined index
this the results I'm getting :
Array([id] => 21240 [email] => my@gmail.com [url] => somewebsite.com [domains] => another_domain [progress] => 198 [total] => 199 [别名] =>测试项目3 [状态] =>完成
Array ( [id] => 21240 [email] => my@gmail.com [url] => somewebsite.com [domains] => another_domain [progress] => 198 [total] => 199 [alias] => Test Project #3 [status] => complete )
正如您可以清楚地看到的那样,progress
索引非常合适.
And well as you can obviously see for yourself, the progress
index is perfectly there.
那么,问题可能出在哪里呢?那是任何奇怪的CI错误吗?
So, what could the issue be? Is that any weird know CI bug?
这是var_dump($proj,$proj['progress']);
给出的:
array(8) {
["id"]=>
string(5) "21240"
["email"]=>
string(20) "my@gmail.com"
["url"]=>
string(27) "somewebsite.com"
["domains"]=>
string(84) "another_domain"
["progress"]=>
string(3) "198"
["total"]=>
string(3) "199"
["alias"]=>
string(15) "Test Project #3"
["status"]=>
string(8) "complete"
}
string(3) "198"
推荐答案
应为:
mysite.com/CONTROLLER/results/45/4
这篇关于未定义的索引...现有索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!