我刚刚完成通过Xampp在本地构建网站。一切正常,它使用PHP 5.6版本。我使用作曲家来使用一些第三方应用程序,如Guzzle和Stringy。完成后,我上传到我的Godaddy webhosting帐户,该帐户使用PHP 5.5。当我加载网站我得到这个错误:PHP自定义命名空间不工作
致命错误:类“利布斯\型号\ Site_Settings”不是的public_html /门/ conf目录/ settings.php中发现了线81
但是厂商的命名空间只是工作精细。我没有得到任何错误。赫克我没有得到任何错误与我的自定义类。我正在使用作曲家自动载入所有内容。一切都在本地完美运行,任何使用自定义命名空间的类都不能只在我的虚拟主机帐户上运行。在我的课我都在上面:
namespace Libs\Model;
我还用括号
namespace Libs\Model {\\code here}
试图研究这个问题,想出什么尝试。有什么建议么?在psr4自动加载文件中显示:
'Libs\\' => array($baseDir . '/lib')
我验证了$ baseDir指向正确的文件夹。
UPDATE
这里是从类进出口试图调用代码。很简单:
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"
}
}
我刚添加的代码。这有帮助吗? – John
Site_Settings.php和./vendor/ –
在哪里从主目录:\ lib \ vendor \ model \ site_settings.php哦,man是一个区分大小写的问题吗?废话,如果这是我即时愚蠢作为地狱 – John