Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何与laravel一起使用包含文件?_Php_Include_Laravel 4 - Fatal编程技术网

Php 如何与laravel一起使用包含文件?

Php 如何与laravel一起使用包含文件?,php,include,laravel-4,Php,Include,Laravel 4,我正在使用Laravel,我为我的项目找到了一个图表库。此库()是php,它使用以下内容: include "../libchart/classes/libchart.php"; 但如果我将此代码放在视图中,则会出现以下错误: include(../libchart/classes/libchart.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such

我正在使用Laravel,我为我的项目找到了一个图表库。此库()是php,它使用以下内容:

include "../libchart/classes/libchart.php";
但如果我将此代码放在视图中,则会出现以下错误:

include(../libchart/classes/libchart.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory
然后我粘贴:

myproject
->app
  ->views
    ->libchart
      ->libchart
      ->demo
包括“./libchart/classes/libchart.php”是:

libchart
->libchart
->demo
  ->LineChartTest.php
编辑:

Route::get('pruebaimagen', function() {
    include_once(app_path() . '/librerias/libchart/classes/libchart.php');
    return View::make('demo.LineChartTest');
});
<?php
/* Libchart - PHP chart library
 * Copyright (C) 2005-2011 Jean-Marc Trémeaux (jm.tremeaux at gmail.com)
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

/**
 * Line chart demonstration
 *
 */

$chart = new LineChart();

$dataSet = new XYDataSet();
$dataSet->addPoint(new Point("06-01", 273));
$dataSet->addPoint(new Point("06-02", 421));
$dataSet->addPoint(new Point("06-03", 642));
$dataSet->addPoint(new Point("06-04", 799));
$dataSet->addPoint(new Point("06-05", 1009));
$dataSet->addPoint(new Point("06-06", 1406));
$dataSet->addPoint(new Point("06-07", 1820));
$dataSet->addPoint(new Point("06-08", 2511));
$dataSet->addPoint(new Point("06-09", 2832));
$dataSet->addPoint(new Point("06-10", 3550));
$dataSet->addPoint(new Point("06-11", 4143));
$dataSet->addPoint(new Point("06-12", 4715));
$chart->setDataSet($dataSet);

$chart->setTitle("Sales for 2006");
$chart->render("recursos/demo5.png");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Libchart line demonstration</title>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15" />
</head>
<body>
    <img alt="Line chart" src="generated/demo5.png" style="border: 1px solid gray;"/>
</body>
</html>
我试过这个:

  • 我在app中创建了一个名为grafico的目录
  • 我这样做:

    Route::get('pruebaimagen',function(){
    包括一次(app_path()。/grafico/libchart/classes/libchart.php);
    $data['libchart']=新的libchart();
    返回视图::make('template',$data);
    });

  • 返回视图::make('template',$data)我必须使用哪种类型的模板?我现在得到了这个错误:

    Class 'Libchart' not found
    

    不要将文件包括在视图文件夹中

    app
    目录中创建一个名为
    anythingFolder
    的自定义文件夹,然后将库粘贴到那里

    现在,将您的文件包括在您想要使用它的控制器方法中,如下所示:

    public function index() {
        include_once(app_path() . '/anythingFolder/libchart/classes/libchart.php');
        $data['libchart'] = new Libchart()
        return View::make('template', $data);
    }
    
    根据需要改进上述代码


    读这篇

    我终于做到了。拉希尔·瓦齐尔帮助了我,现在我的项目开始运作了

    我的路线:

    Route::get('pruebaimagen', function() {
        include_once(app_path() . '/librerias/libchart/classes/libchart.php');
        return View::make('demo.LineChartTest');
    });
    
    <?php
    /* Libchart - PHP chart library
     * Copyright (C) 2005-2011 Jean-Marc Trémeaux (jm.tremeaux at gmail.com)
     * 
     * This program is free software: you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation, either version 3 of the License, or
     * (at your option) any later version.
     * 
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     * 
     */
    
    /**
     * Line chart demonstration
     *
     */
    
    $chart = new LineChart();
    
    $dataSet = new XYDataSet();
    $dataSet->addPoint(new Point("06-01", 273));
    $dataSet->addPoint(new Point("06-02", 421));
    $dataSet->addPoint(new Point("06-03", 642));
    $dataSet->addPoint(new Point("06-04", 799));
    $dataSet->addPoint(new Point("06-05", 1009));
    $dataSet->addPoint(new Point("06-06", 1406));
    $dataSet->addPoint(new Point("06-07", 1820));
    $dataSet->addPoint(new Point("06-08", 2511));
    $dataSet->addPoint(new Point("06-09", 2832));
    $dataSet->addPoint(new Point("06-10", 3550));
    $dataSet->addPoint(new Point("06-11", 4143));
    $dataSet->addPoint(new Point("06-12", 4715));
    $chart->setDataSet($dataSet);
    
    $chart->setTitle("Sales for 2006");
    $chart->render("recursos/demo5.png");
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Libchart line demonstration</title>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15" />
    </head>
    <body>
        <img alt="Line chart" src="generated/demo5.png" style="border: 1px solid gray;"/>
    </body>
    </html>
    
    Mi视图:

    Route::get('pruebaimagen', function() {
        include_once(app_path() . '/librerias/libchart/classes/libchart.php');
        return View::make('demo.LineChartTest');
    });
    
    <?php
    /* Libchart - PHP chart library
     * Copyright (C) 2005-2011 Jean-Marc Trémeaux (jm.tremeaux at gmail.com)
     * 
     * This program is free software: you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation, either version 3 of the License, or
     * (at your option) any later version.
     * 
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     * 
     */
    
    /**
     * Line chart demonstration
     *
     */
    
    $chart = new LineChart();
    
    $dataSet = new XYDataSet();
    $dataSet->addPoint(new Point("06-01", 273));
    $dataSet->addPoint(new Point("06-02", 421));
    $dataSet->addPoint(new Point("06-03", 642));
    $dataSet->addPoint(new Point("06-04", 799));
    $dataSet->addPoint(new Point("06-05", 1009));
    $dataSet->addPoint(new Point("06-06", 1406));
    $dataSet->addPoint(new Point("06-07", 1820));
    $dataSet->addPoint(new Point("06-08", 2511));
    $dataSet->addPoint(new Point("06-09", 2832));
    $dataSet->addPoint(new Point("06-10", 3550));
    $dataSet->addPoint(new Point("06-11", 4143));
    $dataSet->addPoint(new Point("06-12", 4715));
    $chart->setDataSet($dataSet);
    
    $chart->setTitle("Sales for 2006");
    $chart->render("recursos/demo5.png");
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Libchart line demonstration</title>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15" />
    </head>
    <body>
        <img alt="Line chart" src="generated/demo5.png" style="border: 1px solid gray;"/>
    </body>
    </html>
    
    我在中添加了这个:“app/librerias”


    然后我运行了cmd:composer dump autoload,它成功了。

    忘记幼虫中核心PHP的复杂代码,因为Laravel提供了一个函数,用于在for blade模板代码中添加许多文件

    @include('foldername.filename')
    
    @include('filename')
    

    它们是纯Laravel函数。

    您将库文件放在了哪里?您似乎不具备Laravel的基本知识。是吗?不,我从这个开始。我只是把我的代码作为一个示例。你应该自己调整它。这并不是这个问题的真正答案,但根据我在你的例子中看到的情况,你应该知道如何使用
    \uuuu DIR\uuuu
    :这对我不起作用,因为我的雇主希望我
    require()
    自己
    require()的遗留PHP文件
    更多使用相对路径的PHP文件。你知道有什么方法可以恢复普通的
    require()
    行为吗?