需要有关 Codeigniter gchart 帮助使用的帮助

发布于 2024-10-30 07:43:26 字数 2771 浏览 0 评论 0原文

我按照 wiki 文章 (http://codeigniter.com/wiki/gchart/revision/5312/) 在我的 CI 2.0 中练习 google 图表。 但这不起作用。

控制器文件:ci\application\helpers\mytest.php

$this->load->helper( 'gchart' );
$this->load->view('my_test');

查看文件: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;

帮助文件:ci\application\helpers\gchart_helper.php

// I do copied all the source code from the wiki url link above.

当我尝试通过 CI 绘制图表时。 它显示错误是这样的, 解析错误:语法错误,意外的“;”在 C:\xampp\htdocs\demo\ci\application\views\my_test.php 第 54 行

我的操作有什么问题吗? 我比较了 gchart_helper.php 中的extendencode()

function extendedencode($data, &$maxvalue='notspecified')

和 my_test.php 中的extendencode()

$encoded_data = extendedencode(array(0, 1, 2, 3, 4, 5, 6) &maxvalue;);

然后我将 my_test.php 视图文件中的extendencode() 行更新为此,

$encoded_data = extendedencode(array(0, 1, 2, 3, 4, 5, 6), &maxvalue);

然后重试,但仍然出现下面的错误。

解析错误:语法错误,意外的“)”,第 54 行 C:\xampp\htdocs\demo\ci\application\views\my_test.php 中期待 T_PAAMAYIM_NEKUDOTAYIM

非常感谢任何帮助或评论。

[已更新]

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

[根据 Frank 的建议更新]

下面仍然出现两个错误,

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}

I followed the wiki artichle (http://codeigniter.com/wiki/gchart/revision/5312/) to practice google chart in my CI 2.0.
But it doesn't work.

controller file: ci\application\helpers\mytest.php

$this->load->helper( 'gchart' );
$this->load->view('my_test');

view file: 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

// I do copied all the source code from the wiki url link above.

When I try to charted by CI.
It showed error as this,
Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\demo\ci\application\views\my_test.php on line 54

Any thing wrong on my operation?
I compared the extendedencode() from gchart_helper.php

function extendedencode($data, &$maxvalue='notspecified')

and extendedencode() from my_test.php

$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,

$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

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}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红焚 2024-11-06 07:43:26

亚历克斯的回答在语法上不正确。尝试:

$encoded_data = extendedencode(array(0, 1, 2, 3, 4, 5, 6), $maxvalue);

&函数文档中只是告诉您变量将通过引用使用。您不应该(事实上不能)包含 &当你调用该函数时。在旧版本的 PHP 中,有一个名为“调用时传递引用”的功能,您可以在其中使用类似的语法,但在最新版本中不允许这样做。

编辑:

关于您列出的其他错误之一:如错误所示,您向我们展示的代码中没有 $encoded var 。尝试用 &chd;:e{$encoded_data} 替换 &chd;:e{$encoded} ——我猜这可能就是你想要的。

消除最终错误的一种草率方法是将 $ret .= $grid[$x].$grid[$y]; 替换为 $ret .= @$grid[$ x].@$grid[$y];。如果没有正在运行的代码的附加上下文,很难说出实际的根本问题是什么。

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.

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. Try replacing &chd;:e{$encoded} with &chd;:e{$encoded_data} -- I'm guessing that might be what you intended.

A sloppy method of silencing the final error would be to replace $ret .= $grid[$x].$grid[$y]; with $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.

深居我梦 2024-11-06 07:43:26

我认为这一行的分号很糟糕:

$encoded_data = extendedencode(array(0, 1, 2, 3, 4, 5, 6) &maxvalue;);

就在 &maxvalue 之后。

拿出来试试?

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.

Try taking it out?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文