phpzend-framework2fatal-errorzend-framework3

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


I am sharing some lines of code here which I am doing. my other validators are working currently but URI validator gives this error "Fatal error: Uncaught Error: Class 'Zend\Uri\Uri' not found" when i going to this path "http://localhost/applications/add". I have already added Zend URI validator in "vendor\zendframework\zend-validator\src\Uri.php"(for this I am sharing screen shot also).

<?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'
                    ],
                ],
            ]
        );
)
}
?>

This is code of "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
{
}
?>

this is my folders structure where Uri.php is exist

screen shot of error which I am getting


Solution

  • Class Zend/Uri/Uri is part of another package, zendframework/zend-uri, which is suggested by the validator. Take a look on line 44 of zend-uri composer.json:

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

    To solve this problem, execute this command from the project's root folder:

    composer require zendframework/zend-uri