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 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等