建立phpChart在laravel [英] setting up phpChart in laravel
问题描述
环境:亚马逊EC2。 Ubuntu的64。 (GD库安装) 我最近使用phpChart的图形和报告laravel框架。 我停留在起步阶段。
下面是我做了什么。
- 1.Unzip的在phpChart_Lite内容到/ var /网络/应用程序/库/ phpChart。
-
2.Edit composer.json并添加:
自动加载:{ classmap:[ ... 应用程序/库 ] },
-
3.run:作曲家转储自动加载
-
4.modify conf.php在phpChart_Lite
定义(SCRIPTPATH',APP_PATH()'/库/ phpChart_Lite /');
下面是我的测试页code:
< PHP
require_once(APP_PATH()/库/ phpChart_Lite / conf.php。);
$ PC =新C_PhpChartX(阵列(阵列(11,09 5,12,14)),'basic_chart');
$ PC->平局();
?>
ps.my APP_PATH()用回声APP_PATH()证实,它是/无功/网络/应用程序。
这是我的错误信息:
未知:失败需要开放'/var/www/public//var/www/app/libraries/phpChart_Lite//conf.php
(include_path中=/无功/网络/供应商/ phpseclib / phpseclib / phpseclib:。:在/ usr /共享/ PHP的:在/ usr /共享/梨)
在很多的尝试和错误,我不知怎么找到了病根,我猜。 实际上有两个主要的问题在那里。下面是我的解决方案。
在第一个帖子1.适用于我的问题解释。 在phpChart_Lite文件夹中的conf.php文件。该SCRIPTPATH以某种方式$ pfixed有/无功/网络/公共p $。
不过,在我apache2.conf文件状态的目录是在/ var / WWW。无论此preFIX,我用SCRIPTPATH一个绝对路径。下面的修改对我的作品:
定义(SCRIPTPATH','.. /程序/库/ phpChart_Lite /');
错误不见了。但是第二个问题会出现,这是图表显示不出来。 打开Chrome开发人员工具(preSS F12)。在控制台选项卡中,我发现了错误404装载phpChar_Lite / JS。一个错误信息如下:
HTTP://myip/app/libraries/phpChart_Lite/js/highlighter/styles/zenburn.css
由于Laravel的设计,唯一的公共文件夹可以通过外部请求访问。 所以,我得到了第二个问题。下面是我的解决方案。(不是受保护的方法)
2.移动的phpChart_Lite公共文件夹。修改测试页的code:
include_once(public_path()/ phpChart_Lite / conf.php。);
修改conf.php公共/ phpChart_Lite:
定义(SCRIPTPATH','phpChart_Lite /');
一切都就好了。
如果你考虑phpChart过于复杂的配置搭配,你可能想尝试pChart2.0。 它并不需要多大的设置。但该图是非常难看。
我preFER phpChart为它的图形和函数调用,虽然设置有点复杂,不laravel友好。
Environment:Amazon EC2. Ubuntu x64. (GD library installed) I'm recently using phpChart for graph and report in laravel framework. I'm stuck at the beginning stage.
Here's what I've done.
- 1.Unzip the contents in phpChart_Lite to /var/www/app/libraries/phpChart.
2.Edit composer.json and add :
"autoload": { "classmap": [ ... "app/libraries" ] },
3.run:composer dump-autoload
4.modify conf.php in phpChart_Lite
define('SCRIPTPATH',app_path().'/libraries/phpChart_Lite/');
Here's my test page code:
<?php
require_once(app_path()."/libraries/phpChart_Lite/conf.php");
$pc = new C_PhpChartX(array(array(11, 9, 5, 12, 14)),'basic_chart');
$pc->draw();
?>
ps.my app_path() is verified by "echo app_path()" and it is "/var/www/app".
Here's my error message:
Unknown: Failed opening required '/var/www/public//var/www/app/libraries/phpChart_Lite//conf.php'
(include_path='/var/www/vendor/phpseclib/phpseclib/phpseclib:.:/usr/share/php:/usr/share/pear')
After a lot of try-and-error, I somehow found the root cause, I guess. There are actually two main issue there. And here's my solution.
1.For my issue explained in the very first post. In the conf.php file in phpChart_Lite folder. The SCRIPTPATH is somehow prefixed with /var/www/public.
However, in my apache2.conf file states the directory to be /var/www. Regardless this prefix, I use a absolute path for SCRIPTPATH. The following modification works for me:
define('SCRIPTPATH','../app/libraries/phpChart_Lite/');
The error was gone. But the second issue appears, that is the chart doesn't show up. Open the Chrome Developer Tool(press F12). On the 'Console' tab, I found error 404 for loading phpChar_Lite/js. One of the error messages as following:
http://myip/app/libraries/phpChart_Lite/js/highlighter/styles/zenburn.css
As the design of Laravel, only public folder can be access by external request. So I got second issue. And here's my solution.(not a secured method)
2.Move the phpChart_Lite to public folder. Modify the code of test page:
include_once(public_path()."/phpChart_Lite/conf.php");
Modify the conf.php in public/phpChart_Lite:
define('SCRIPTPATH','phpChart_Lite/');
Everything's just fine now.
If you consider phpChart is too complicate to configure with, you might want to try pChart2.0. It doesn't require much setting. But the graph is terribly ugly.
I prefer phpChart for it's graph and function calls, though the setting is a little complicated and not laravel friendly.
这篇关于建立phpChart在laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!