PHP自定义命名空间不起作用

约翰

我刚刚通过Xampp在本地建立了一个站点。一切正常,使用PHP 5.6。我曾使用作曲家使用一些第三方应用程序,例如Guzzle和Stringy。完成后,我上载到使用PHP 5.5的Godaddy虚拟主机帐户。当我加载网站时,出现此错误:

致命错误:在第81行的public_html / portal / conf / settings.php中找不到类'Libs \ Model \ Site_Settings'

但是,供应商名称空间可以正常工作。我没有任何错误。哎呀,我的自定义类没有任何错误。我正在使用作曲家自动加载所有内容。一切都在本地完美运行,只是我使用自定义名称空间的所有类都仅在我的Web托管帐户上不起作用。在我的课程中,我排在最前面:

namespace Libs\Model;

我也尝试使用方括号

namespace Libs\Model {\\code here}

试图研究此问题,但一无所获。有什么建议么?在psr4自动加载文件中,它显示:

'Libs\\' => array($baseDir . '/lib')

我验证$ baseDir指向正确的文件夹。

更新

这是Im试图调用的类中的代码。很简单的:

namespace Libs\Model;

class Site_Settings {

    private $dbconn;

    public function __construct($dbconn)
    {

        $this->dbconn = $dbconn;            

    }

    public function findSiteSettings($domain)
    {

        //We clean any variables being passed to the query
        $domain = $this->dbconn->escape($domain);

        //We turn on query caching
        $this->dbconn->cache_queries = TRUE;

        //This is the query statement to run
        $query = $this->dbconn->get_row("
                SELECT
                    jp.*,
                    js.stateabb,
                    js.statename,
                    js.statecountry
                FROM
                    job_site AS jp
                INNER JOIN
                    job_state AS js
                ON
                    jp.stateid = js.id
                WHERE
                    jp.sitedomain = '$domain'
                AND
                    jp.active = 1
                LIMIT
                    1
                ");

        //We turn off query caching
        $this->dbconn->cache_queries = FALSE;

        //We now return any rows found
        return $query;

    }

}

我是这样称呼它的:

//We include the autoloader that is needed to load all vendors for this site
    include(VENDORS .'autoload.php');

    //We get the site settings for this job site
    $settings = new Libs\Model\Site_Settings($global_db);
    $site_settings = $settings->findSiteSettings($global_sitedomain);

这是我从composer中为psr4自动加载的文件:

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname(dirname($vendorDir));

return array(
    'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'),
    'Stringy\\' => array($vendorDir . '/danielstjules/stringy/src'),
    'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-message/src'),
    'Libs\\' => array($baseDir . '/lib'),
    'League\\Plates\\' => array($vendorDir . '/league/plates/src'),
    'GuzzleHttp\\Psr7\\' => array($vendorDir . '/guzzlehttp/psr7/src'),
    'GuzzleHttp\\Promise\\' => array($vendorDir . '/guzzlehttp/promises/src'),
    'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'),
    'Cocur\\Slugify\\' => array($vendorDir . '/cocur/slugify/src'),
);

更新#2这是我的作曲家文件

    "autoload": {
        "classmap": [
            "lib/vendor/ezsql/mysqli/ez_sql_mysqli.php",
            "lib/vendor/ezsql/shared/ez_sql_core.php",
            "lib/helper/url.php",
            "lib/helper/html.php",
            "lib/helper/form_message.php",
            "lib/helper/email_generator.php",
            "lib/helper/pagination.php"
        ],
        "psr-4": {"Libs\\": "lib"}
    },
    "require": {
        "league/plates": "^3.1",
        "guzzlehttp/guzzle": "^6.2",
        "phpmailer/phpmailer": "^5.2",
        "cocur/slugify": "^2.1",
        "danielstjules/stringy": "^2.3",
        "wixel/gump": "^1.3",
        "jwage/purl": "^0.0.7"
    }
}
亚历克斯·巴克

您没有提供足够的信息来真正回答您的问题。用于Libs \ Model \ Site_Settings的php文件在哪里?您是否正在开发一个不区分大小写的系统,例如OSX,并上传到一个区分大小写的系统,例如Linux?您正在使用哪种自动加载标准?看起来您正在同时使用PSR-0和PSR-4。

您可能需要向composer.json添加自动加载路径:

    "autoload": {
        "psr-4": {
            "Libs\\Model\\": "lib/src/model",

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章