简体   繁体   English

php 在 file.php 中找不到 HeadlessChromium\BrowserFactory

[英]php HeadlessChromium\BrowserFactory not found in file.php

<?php
use HeadlessChromium\BrowserFactory;

$browserFactory = new BrowserFactory();

?>

I've installed chrome-php/chrome with composer and hovering my mouse over the class will give me the details but when I try to run the code I get the error:我已经使用 composer 安装了 chrome-php/chrome,将鼠标悬停在 class 上会显示详细信息,但是当我尝试运行代码时出现错误:

PHP Fatal error:  Uncaught Error: Class 'HeadlessChromium\BrowserFactory' not found in file.php

Is there something I'm missing in the initial set up?我在初始设置中缺少什么吗? Not sure why it isn't working.不知道为什么它不工作。 I'm using visual studio code and the bug appears in the debug console tab instead of the problems tab.我正在使用 visual studio 代码,错误出现在调试控制台选项卡而不是问题选项卡中。 I'm not getting any issues in the problems tab.我在问题选项卡中没有遇到任何问题。 Any idea why that is the case?知道为什么会这样吗?

When using composer you need to include the autoloader on top of the script.使用作曲家时,您需要在脚本之上包含自动加载器

<?php
require __DIR__ . '/vendor/autoload.php';

use HeadlessChromium\BrowserFactory;

$browserFactory = new BrowserFactory();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM