【发布时间】:2016-09-14 08:15:50
【问题描述】:
我刚刚通过 Xampp 在本地构建了一个站点。一切正常,它使用 PHP 5.6 版。我使用 composer 来使用一些第三方应用程序,例如 Guzzle 和 Stringy。完成后,我上传到使用 PHP 5.5 的 Godaddy 虚拟主机帐户。当我加载网站时,出现此错误:
致命错误:在第 81 行的 public_html/portal/conf/settings.php 中找不到类“Libs\Model\Site_Settings”
但是,供应商命名空间工作得很好。我没有收到任何错误。哎呀,我的自定义类没有任何错误。我正在使用作曲家自动加载所有内容。一切都在本地完美运行,只是我使用自定义命名空间的任何类都不能仅在我的虚拟主机帐户上运行。在我的班级中,我名列前茅:
namespace Libs\Model;
我也尝试过使用括号
namespace Libs\Model {\\code here}
尝试研究该问题,但一无所获。有什么建议?在 psr4 自动加载文件中显示:
'Libs\\' => array($baseDir . '/lib')
我验证 $baseDir 指向了正确的文件夹。
更新
这是我试图调用的类的代码。很简单:
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);
这是我从作曲家为 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"
}
}
【问题讨论】:
标签: php namespaces composer-php