I am facing this error "Fatal error: Uncaught Error: Class 'Zend\Uri\Uri' not found"

I am facing this error "Fatal error: Uncaught Error: Class 'Zend\Uri\Uri' not found"

我在这里分享我正在做的一些代码行。我的其他验证器目前正在工作,但是当我转到这条路径“http://localhost/applications/add”时,URI 验证器给出了这个错误 "Fatal error: Uncaught Error: Class 'Zend\Uri\Uri' not found"。我已经在 "vendor\zendframework\zend-validator\src\Uri.php" 中添加了 Zend URI 验证器(为此我也分享了屏幕截图)。

<?php
use Zend\Filter;
use Zend\InputFilter\Input;
use Zend\InputFilter\InputFilter;
use Zend\Validator;

class ApplicationsController extends Zend_Controller_Action
{
    public function addAction() {

        $inputFilter = new InputFilter();

        $inputFilter->add(
            [
                'name' => 'web_uri',
                'required' => true,
                'filters' => [
                    ['name' => 'StringTrim'],
                    ['name' => 'HtmlEntities']
                ],
                'validators' => [
                    [
                        'name' => 'NotEmpty'
                    ],
                    [
                        'name' => 'Uri'
                    ],
                ],
            ]
        );
)
}
?>

这是"zendframework\zend-validator\src\Uri.php"

的代码
<?php
namespace Zend\Validator;

use Traversable;
use Zend\Uri\Exception\ExceptionInterface as UriException;
use Zend\Uri\Uri as UriHandler;
use Zend\Validator\Exception\InvalidArgumentException;

class Uri extends AbstractValidator
{
}
?>

Class Zend/Uri/Uri 是验证者建议的另一个包 zendframework/zend-uri 的一部分。看看 line 44 of zend-uri composer.json:

...
    "suggest": {
...
        "zendframework/zend-uri": "Zend\Uri component, required by the Uri and Sitemap\Loc validators"
    },
...

要解决此问题,请从项目的根文件夹执行此命令:

composer require zendframework/zend-uri

您的项目中没有安装 zend-uri 包。 所以你已经按照link安装过程。

运行在你的项目根目录下执行以下命令

$ composer require zendframework/zend-uri