-1

I am trying to validate email while registration to makesure no spam. For that purpose i learn that, Zend FrameWork is good for this.

So to try that following steps i followed:

  1. i downloaded ZendFramework-2.4.13.zip from https://framework.zend.com/downloads/archives
  2. I extract in the same path of my file and rename folder to ZendFramework
  3. Then i try following code, as guided in their tutorial.
    require_once("ZendFramework/library/Zend/Validator/EmailAddress.php");
    
    $validator = new Zend\Validator\EmailAddress();
    $email = "[email protected]";
    if ($validator->isValid($email)) {
        echo "Valid \n";
    } else {
        // email is invalid; print the reasons
        foreach ($validator->getMessages() as $message) {
            echo "$message\n";
        }
    }

But when i am running code, i got following error, i even checked the zend source class, but it seems normal.

PHP Fatal error: Uncaught Error: Class 'Zend\Validator\AbstractValidator' not found in /home/account_name/public_html/test_mail/ZendFramework/library/Zend/Validator/EmailAddress.php:12

Stack trace: #0 /home/account_name/public_html/test_mail/email-test.php(2): require_once()

#1 {main} thrown in /home/account_name/public_html/test_mail/ZendFramework/library/Zend/Validator/EmailAddress.php on line 12

Need experts help, what i am doing wrong, do i need to only call it by extending class?

Update I also tried following, but still same error

ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . '/home/account_name/public_html/test_mail/ZendFramework/library/');
require_once("Zend/Validator/EmailAddress.php");

1 Answer 1

0

I'd strongly recommend using Composer to handle your dependencies, and its autoloader to handle loading classes. Life is much simpler that way.

Assuming that you have installed components with composer require ..., and assuming that you've followed the normal directory layout for a Laminas/Zend Framework 2 applications, then you just include the following in your index.php file:

require __DIR__ . '/../vendor/autoload.php'

It should be as simple as that: classes will be loaded without you having to require the individual files. If you make any changes to the autoload section in composer.json, make sure to dump the autoloader configuration again:

composer dump-autoload

Also, Zend Framework has been replaced by Laminas; Zend Framework is no longer maintained, so you're missing out on bug fixes, security patches and new features. Laminas documentation is here: you'll want Laminas MVC and Laminas Components.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.