Slim
Slim

Reputation: 1744

Phalcon's universal class loader can't find my class

As a total php and phalcon newbie, I'm trying to use the recommended universal class loader using this code:

$loader = new \Phalcon\Loader();

// Register some directories
$loader->registerDirs(
    array(
        "php/assistants/"
    )
);

// register autoloader
$loader->register();

$test = new dbAssistant();

as I understand I have to reffer to the php file as a class what I have inside of php/assistants/dbAssistant.php is the following code, trying to connect to a database:

<?php

function connect() { 
    $connection = new Phalcon\Db\Adapter\Pdo\Mysql(array(
        'host' => 'localhost',
        'username' => 'root',
        'password' => 'tt',
        'dbname' => 'testdb',
        'port' => '3306'
    ));
    echo 'Connected!!!';
}

again what I understand is that I have to refer to dbAssistant.php as a class and that's why I'm using $test = new dbAssistant();, but it gives me the following error:

Fatal error: Class 'dbAssistant' not found in /var/www/html/test/test.php on line 18

I know that it seeme normal, but the strange thing is that if I remove the connect() function and place the code out of it, I can see the Connected!!! echo, but it is followed by the same(above) error. I know that I'm missing something really small here, but as a complete php newbie, I really can't spot the problem.

Can you give me a push?

Upvotes: 0

Views: 186

Answers (1)

Waaghals
Waaghals

Reputation: 2609

php/assistants/dbAssistant.php is not a class but a plain Php file. There should be a class in there with the name dbAssistant.

class dbConnect {

    public function connect() {
        ///Do your stuff
    }
}

Upvotes: 1

Related Questions