dongzhi2887 2016-09-02 19:17
浏览 44
已采纳

在我的项目中找不到PHP库

I'm not a web dev (I'm a mobile developer) and trying to figure this out.

  1. I'm using this library: https://github.com/ktamas77/firebase-php

  2. I got 'composer' installed on my machine by following the documentation on composer's site.

  3. I have installed the library in #1 by using this command: 'php composer.phar require ktamas77/firebase-php dev-master'

  4. In a certain screen or php file in my project, I'm adding this:

    $firebase = new \Firebase\FirebaseLib(DEFAULT_URL, DEFAULT_TOKEN);

and when I run or go to that specific screen, there's an error like this:

Message: Class 'Firebase\FirebaseLib' not found

My question is: Why is that? Why can't this freakin php project find that FirebaseLib? I can verify that I have such file in my project, cause I can open the file from that code above.

The path of that file is this:

'/Applications/MAMP/htdocs/xxx-cms/vendor/ktamas77/firebase-php/src/firebaseLib.php'

Is adding 'require' at the top of my php file required?

I tried adding require but the error goes to that require when adding that.

Lastly, I even modified my composer.json and added "autoload" as was suggested here: How does PHP connection to firebase work?

{
    "description": "The CodeIgniter framework",
    "name": "codeigniter/framework",
    "type": "project",
    "homepage": "https://codeigniter.com",
    "license": "MIT",
    "support": {
        "forum": "http://forum.codeigniter.com/",
        "wiki": "https://github.com/bcit-ci/CodeIgniter/wiki",
        "irc": "irc://irc.freenode.net/codeigniter",
        "source": "https://github.com/bcit-ci/CodeIgniter"
    },
    "require": {
        "php": ">=5.2.4",
        "ktamas77/firebase-php": "dev-master"
    },
    "suggest": {
        "paragonie/random_compat": "Provides better randomness in PHP 5.x"
    },
    "require-dev": {
        "mikey179/vfsStream": "1.1.*"
    },
    "autoload": {
        "classmap": ["vendor/ktamas77/firebase-php/src/firebaseLib.php"]
        "files": ["vendor/ktamas77/firebase-php/src/firebaseLib.php"]
    }

}

Unfortunately I wasn't able to do this instruction from that SO answer:

Then simply require Composer's Autoloader with require "vendor/autoload.php"; and new Firebase to autoload the class.

Thanks.

  • 写回答

1条回答 默认 最新

  • dongtun3259 2016-09-02 19:52
    关注

    You need to add the autoloader from composer into your base script or some bootstrap file.

    Something like:

    require "vendor/autoload.php";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料