質問

I'm trying to get working use.

My file is in /application/controllers/indexController.php

use application\models\Database;

class IndexController extends Controller {

    public function indexAction() {
        $db = new Database();
        $this->view->render('index','template');
    }
}

My Database class is in /application/models/Database.php so i wrote use application\models\Database

But it tells

Fatal error: Class 'application\models\Database' not found in Z:\home\localhost\www\application\controllers\IndexController.php on line 7

How i can get it worked?

役に立ちましたか?

解決

use is not magical.

You need an autoloader to tell it where to find a certain namespace.

So right now your code is looking for a class called application\models\Database in the same directory as your currently executing file.

I think what you meant to do is:

include 'application\models\Database.php';
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top