Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.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脚本中的类?_Php_Laravel - Fatal编程技术网

如何在项目中调用php脚本中的类?

如何在项目中调用php脚本中的类?,php,laravel,Php,Laravel,我想创建一个php脚本来查询所有帐户。 因为我已经有了这个类,它已经完成了所有这些,我想利用它并使用它 我试过了 我创建了一个文件调用syncuserstable.php 应用程序\VSE 经典漏分号:) 在修复此问题后,您又出现了一个错误并更新了您的问题。对于您的新问题,您需要在应用程序之前使用反斜杠 <?php use \App\VSE; $accounts = VSE::account_all(); dd($accounts); ?> 但是,不能保证在Larav

我想创建一个php脚本来查询所有帐户。 因为我已经有了这个类,它已经完成了所有这些,我想利用它并使用它


我试过了 我创建了一个文件调用
syncuserstable.php

应用程序\VSE
经典漏分号:)

在修复此问题后,您又出现了一个错误并更新了您的问题。对于您的新问题,您需要在应用程序之前使用反斜杠

<?php

use \App\VSE;

$accounts = VSE::account_all();
dd($accounts);

?>

但是,不能保证在Laravel项目中运行solo文件会成功

当然,存在依赖性和自动装入的考虑因素。


在您的VSE类中,您使用的是在shell中运行php文件时未知的laravel函数。

错误说明了一切,php解释器遇到了T_变量
$accounts
,但需要一个“,”或“;”在那之前


在本例中,第3行末尾的分号将解决您的问题。

我注意到我必须将此
require_一次性添加到“vendor/autoload.php”


缺少
后使用App\VSE
,仍然得到这个。不可能。您确定保存了更改吗?函数
account\u all()
在哪里定义?是的,先生>保存>并重新运行>php syncuserstable.phpcomon这不是重点!我已经添加了它,我仍然得到这个
致命错误:在第5行的/Applications/MAMP/htdocs/code/benu/ssc portal/syncuserstable.php中找不到类'App\VSE',
@ihue,但这不是你在问题中显示的,你正在显示上面答案正确回答的错误。新错误是另一个错误。那是另一个错误。没有这样的课程。您是否阅读了错误消息?可能是因为没有自动加载器而无法访问该类。
use\App\VSE-->仍然看到
PHP致命错误:在第5行的/Applications/MAMP/htdocs/code/benu/ssc portal/syncuserstable.PHP中找不到类“App\VSE”
Cool,因此您得到了结果。感谢@Jite
PHP Fatal error:  Class 'App\VSE' not found in /Applications/MAMP/htdocs/code/site/portal/syncuserstable.php on line 5
<?php
    namespace App;

    class VSE {
        public static function account_all() {
            $url = env('API_HOST').'vse/accounts';
            return Helper::getData($url);
        }
    }
<?php

use \App\VSE;

$accounts = VSE::account_all();
dd($accounts);

?>
<?php

require_once "vendor/autoload.php";
use \App\VSE;

// require_once('/app/VSE.php');

$accounts = VSE::account_all();
dd($accounts);

?>
array:10 [
  0 => array:28 [
    "email_address" => "admin@benunets.com"
    "password" => "admin"
    "account_id" => 1000
    "account_type" => "admin"
    "name_prefix" => null
    "first_name" => null
    "middle_names" => null
    "last_name" => "Admin"
    "name_suffix" => null
    "non_person_name" => false
    "dba" => ""
    "display_name" => "Admin"
    "address1" => "111 Park Ave"
    "address2" => "Floor 4"
    "address3" => "Suite 4011"
    "city" => "New York"
    "state" => "NY"
    "postal_code" => "10022"
    "nation_code" => "USA"
    "phone1" => "212-555-1212"
    "phone2" => ""
    "phone3" => ""
    "time_zone_offset_from_utc" => -5
    "customer_type" => 2
    "last_updated_utc_in_secs" => 1446127072
    "longitude" => null
    "latitude" => null
    "altitude" => null
  ]
  1 => array:28 [
    "email_address" => "mhn@benu.com"
    "password" => "benu123"
    "account_id" => 1002
    "account_type" => "customer"
    "name_prefix" => ""
    "first_name" => "MHN"
    "middle_names" => ""
    "last_name" => "User"
    "name_suffix" => ""
    "non_person_name" => false
    "dba" => ""
    "display_name" => "MHNUser"
    "address1" => "11 Peterborough Street"
    "address2" => ""
    "address3" => ""
    "city" => "Boston"
    "state" => "MA"
    "postal_code" => "02215"
    "nation_code" => "USA"
    "phone1" => "44444"
    "phone2" => ""
    "phone3" => ""
    "time_zone_offset_from_utc" => -5
    "customer_type" => 2
    "last_updated_utc_in_secs" => 1469132442
    "longitude" => -71.0957612
    "latitude" => 42.3442383
    "altitude" => 0
  ]