Knight Yoshi
Knight Yoshi

Reputation: 994

Yii2 reCaptcha Widget Class Not Found

So I'm trying to use the Yii2 reCaptcha widget: http://www.yiiframework.com/extension/yii2-recaptcha-widget/

However, when setting the validation rule for it

['reCaptcha'], \himiklab\yii2\recaptcha\ReCaptchaValidator::className(), 'secret' => Yii::$app->params['reCAPTCHA.secretKey']

I get the error Class 'himiklab\yii2\recaptcha\ReCaptchaValidator' not found. I'm quite new to Composer and Yii2, so I'm not sure what I'm missing.

composer.json

{
    "autoload" : {
        "psr-4" : {
            "Gaiatools\\Yii\\" : "src"
        }
    },
    "name" : "gaiatools/site",
    "require" : {
        "php" : ">=7.0",
        "himiklab/yii2-recaptcha-widget" : "*"
    }
}

vendor/composer/autoload_psr4.php

// autoload_psr4.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
    'yii\\composer\\' => array($vendorDir . '/yiisoft/yii2-composer'),
    'yii\\' => array($vendorDir . '/yiisoft/yii2'),
    'himiklab\\yii2\\recaptcha\\' => array($vendorDir . '/himiklab/yii2-recaptcha-widget'),
    'cebe\\markdown\\' => array($vendorDir . '/cebe/markdown'),
    'Gaiatools\\Yii\\' => array($baseDir . '/src'),
);

Upvotes: 0

Views: 1476

Answers (3)

Mitravind
Mitravind

Reputation: 51

Often you get the error of class not found when the file containing the class definition is not added in current code using namespaces.

Please ensure that you have added the required namespace in file where you are setting the validation rule with following code at the top of file

use himiklab\yii2\recaptcha

Hope this will solve your problem

Upvotes: 0

Nayan Thakkar
Nayan Thakkar

Reputation: 1

Run the following command in a terminal inside your project directory. It will be added automatically in composer.json file.

composer require --prefer-dist "himiklab/yii2-recaptcha-widget" "*" 

Upvotes: 0

Yupik
Yupik

Reputation: 5031

Add this line to require section in project-directory/composer.json file

"himiklab/yii2-recaptcha-widget" : "*"

Then run in project directory command:

composer update

Upvotes: 1

Related Questions