[英]Need help on Codeigniter gchart help usage
I followed the wiki artichle (http://codeigniter.com/wiki/gchart/revision/5312/) to practice google chart in my CI 2.0. 我遵循Wiki artichle(http://codeigniter.com/wiki/gchart/revision/5312/)在我的CI 2.0中练习Google图表。 But it doesn't work.
但这是行不通的。
controller file: ci\\application\\helpers\\mytest.php 控制器文件:ci \\ application \\ helpers \\ mytest.php
$this->load->helper( 'gchart' );
$this->load->view('my_test');
view file: ci\\application\\helpers\\my_test.php 查看文件:ci \\ application \\ helpers \\ my_test.php
$encoded_data = extendedencode(array(0, 1, 2, 3, 4, 5, 6) &maxvalue;);
echo <<< EOS
<img src="
http://chart.apis.google.com/chart?
cht=lc
&chs=250x250
&chd;:e{$encoded}
"
alt="line graph of some example data" />
EOS;
help file: ci\\application\\helpers\\gchart_helper.php 帮助文件:ci \\ application \\ helpers \\ gchart_helper.php
// I do copied all the source code from the wiki url link above.
When I try to charted by CI. 当我尝试按CI绘制图表时。 It showed error as this, Parse error: syntax error, unexpected ';'
它显示了这样的错误, Parse错误:语法错误,意外的';' in C:\\xampp\\htdocs\\demo\\ci\\application\\views\\my_test.php on line 54
在第54行的C:\\ xampp \\ htdocs \\ demo \\ ci \\ application \\ views \\ my_test.php中
Any thing wrong on my operation? 我的操作有什么问题吗? I compared the extendedencode() from gchart_helper.php
我比较了gchart_helper.php中的extendedencode()
function extendedencode($data, &$maxvalue='notspecified')
and extendedencode() from my_test.php 和来自my_test.php的extendedencode()
$encoded_data = extendedencode(array(0, 1, 2, 3, 4, 5, 6) &maxvalue;);
Then I updated the extendedencode() line to this in my_test.php view file, 然后,在my_test.php视图文件中,将extendedencode()行更新为此,
$encoded_data = extendedencode(array(0, 1, 2, 3, 4, 5, 6), &maxvalue);
And try again, but still get this error below. 再试一次,但仍然在下面出现此错误。
Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM in C:\\xampp\\htdocs\\demo\\ci\\application\\views\\my_test.php on line 54 解析错误:语法错误,意外的')',在第54行的C:\\ xampp \\ htdocs \\ demo \\ ci \\ application \\ views \\ my_test.php中期待T_PAAMAYIM_NEKUDOTAYIM
Any help or comments are great appreciated. 任何帮助或评论都将不胜感激。
[updated] [更新]
When I use the formated below,
$encoded_data = extendedencode(array(0, 1, 2, 3, 4, 5, 6) &maxvalue);
showed another four error message.
Events List
A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant maxvalue - assumed 'maxvalue'
Filename: views/my_test.php
Line Number: 54
A PHP Error was encountered
Severity: Warning
Message: max() [function.max]: When only one parameter is given, it must be an array
Filename: helpers/gchart_helper.php
Line Number: 49
A PHP Error was encountered
Severity: Warning
Message: Division by zero
Filename: helpers/gchart_helper.php
Line Number: 55
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: encoded
Filename: views/my_test.php
Line Number: 61
[Updated against Frank's suggestion] [根据弗兰克的建议更新]
There are still two errors occurred below, 下面仍然发生两个错误,
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 64
Filename: helpers/gchart_helper.php
Line Number: 65 // code line: $ret .= $grid[$x].$grid[$y];
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: encoded
Filename: views/my_test.php
Line Number: 61 // code line: &chd;:e{$encoded}
Alex's answer isn't syntactically correct. 亚历克斯的答案在语法上不正确。 Try:
尝试:
$encoded_data = extendedencode(array(0, 1, 2, 3, 4, 5, 6), $maxvalue);
The & in the function documentation just tells you that your variable will be used by reference. 函数文档中的&只是告诉您变量将被引用使用。 You shouldn't (and in fact cannot) include the & when you call the function.
调用函数时,您不应(实际上也不能)包含&。 In older versions of PHP, there was a feature called call-time pass by reference, in which you'd use syntax like that, but it's disallowed in recent versions.
在旧版本的PHP中,有一个称为“按引用传递时间”的功能,在该功能中您将使用类似的语法,但是在最新版本中却不允许使用。
Edit: 编辑:
Regarding one of the additional errors you've listed: as the error says, there's no $encoded
var in the code you've shown us. 关于您列出的其他错误之一:如错误所述,在您显示给我们的代码中没有
$encoded
var。 Try replacing &chd;:e{$encoded}
with &chd;:e{$encoded_data}
-- I'm guessing that might be what you intended. 尝试用
&chd;:e{$encoded}
&chd;:e{$encoded_data}
替换&chd;:e{$encoded}
&chd;:e{$encoded_data}
-我猜这可能就是您想要的。
A sloppy method of silencing the final error would be to replace $ret .= $grid[$x].$grid[$y];
降低最终错误的草率方法是替换
$ret .= $grid[$x].$grid[$y];
with $ret .= @$grid[$x].@$grid[$y];
与
$ret .= @$grid[$x].@$grid[$y];
. 。 Without additional context for the code in play there, it's hard to say what the actual root issue is there.
如果没有正在使用的代码的其他上下文,那么很难说出实际的根本问题是什么。
I think it's a bad semi colon on this line: 我认为这是一个糟糕的分号:
$encoded_data = extendedencode(array(0, 1, 2, 3, 4, 5, 6) &maxvalue;);
right after &maxvalue
. 在
&maxvalue
。
Try taking it out? 尝试拿出来吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.