如何在 Phalcon 中加载外部库


How to load external library in Phalcon?

我正在尝试将Kint加载到我的第一个Phalcon项目中。我正在尝试使用loader.php来做到这一点。我尝试使用"registerDirs","registerClass"和"registerNamespaces"。

我习惯于通过作曲家在 Symfony2 中使用 Kint,但这次我尝试克隆 git 存储库并将其放在这个 Pahlcon 项目的供应商文件夹中。require Kint 类时,我得到的只是一个无声的 500 内部错误。以下是我目前拥有的代码。

<?php
# app/config/loader.php
$loader = new 'Phalcon'Loader();
/**
 * We're a registering a set of directories taken from the configuration file
 */
$loader->registerDirs(
    array(
        $config->application->controllersDir,
        $config->application->modelsDir,
        '~/Code/incubator/Library/Phalcon',
        "vendor/kint"
    )
)->register();

而有问题的控制器:

<?php
# app/controllers/indexController.php
class IndexController extends ControllerBase
{
    public function indexAction()
    {
        Kint::dump("huh");
    }
}

要求作曲家在引导程序中自动加载:

在您的 public/index.php 中,包括作曲家自动加载器:https://github.com/phalcon/forum/blob/master/public/index.php#L44

require realpath('..') . "/vendor/autoload.php";