duankun9280 2014-12-15 20:10
浏览 136
已采纳

Phalcon的通用类加载器无法找到我的类

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?

  • 写回答

1条回答 默认 最新

  • dpo15099 2014-12-15 21:15
    关注

    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
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题