A
A
Alexander Laikov2019-02-10 20:00:54
Yii
Alexander Laikov, 2019-02-10 20:00:54

Connecting PHP file in controller?

Good afternoon!
It is necessary to include a php file of a third-party library.
Located at the root of the folder.
Everything is fine in the view, but how to connect it in the controller?

public function actionGoogle() {
    require_once Yii::$app->basePath.'\google\GoogleAuthenticator.php';
    $ga = new GoogleAuthenticator;
    return $this->render('google', [
      	'ga' => $ga
      ]);

Accordingly, I get an error to the line $ga = new GoogleAuthenticator;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
morricone85, 2019-02-10
@morricone85

Working with third party code

D
Dmitry, 2019-02-10
@slo_nik

Good evening.
Check out the namespace .
Example.
The file is located in the components directory
In the required file, specify the location where the required file is located

//указываете пространство имён
use components\GoogleAuthenticator;

//используете
 $ga = new GoogleAuthenticator;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question