【发布时间】:2013-05-23 21:01:34
【问题描述】:
我想知道在函数中包含()库文件是否被认为是不好的做法?
我的网站的一部分使用了 Sphinx 搜索引擎,但是通过将 sphinxapi.php 添加到我的主站点范围的“配置”文件中来将其添加到每个页面似乎效率低下。
相反,我做了以下事情:
class sphinxSearch
{
/*
* Performs a standard listing search
*/
function listings($filter, $sdb)
{
// include the sphinx api
require_once SITE_INCLUDE_PATH.SEP.'Sphinx/sphinxapi.php';
// set default options
$search = new SphinxClient();
$search->SetServer(SPX_HOST, SPX_PORT);
$search->SetConnectTimeout(1);
$search->SetArrayResult(false);
// blah blah blah
return $result;
}
/*
* Listing autocomplete box
*/
function autoComplete ($query, $sdb)
{
require_once SITE_INCLUDE_PATH.SEP.'Sphinx/sphinxapi.php';
// set default options
$search = new SphinxClient();
$search->SetServer(SPX_HOST, SPX_PORT);
$search->SetConnectTimeout(1);
$search->SetArrayResult(false);
// blah blah blah
}
}
或者我错过了更好的方法吗?
提前致谢。
【问题讨论】:
标签: php coding-style sphinx