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:
- i downloaded ZendFramework-2.4.13.zip from https://framework.zend.com/downloads/archives
- I extract in the same path of my file and rename folder to ZendFramework
- 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");
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 yourindex.phpfile:It should be as simple as that: classes will be loaded without you having to
requirethe individual files. If you make any changes to theautoloadsection incomposer.json, make sure to dump the autoloader configuration again: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.