在引导程序中设置静态方法的默认值
本段是“Zend Framework In Action”一书的一部分。
SearchIndexer::setIndexDirectory(ROOT_DIR . '/var/search_index');
Places_Db_Table_Row_Observable::attachObserver('SearchIndexer');
如您所见,这只是设置搜索索引文件存储目录的情况 并将该类附加到 Places_Db_Table_Row_Observable 中的观察者列表 使用类的名称。
现在我遇到了问题!我将此代码放入 runapp 方法中的 bootstrap 文件中,但它无法识别我在 bootstrap 中设置的目录!
它向我显示了这个错误
An error occurred exception 'Zend_Search_Exception' with message 'No index directory specified' in E:\xampp\php\PEAR\Zend\Search\Lucene.php:497
============================================== ==========
我的问题的其他类型:
我在引导文件(runApp 方法)中有此代码:
SearchIndexer::setIndexDirectory(ROOT_DIR.'/var/search_index');
Places_Db_Table_Row_Observable::attachObserver('SearchIndexer');
我在 SearchIndexer 类中设置搜索目录路径,但有一个问题!
当我在控制器操作中使用以下代码时,它无法识别我在引导程序中设置的目录!
控制器代码:
$index = Places_Search_Lucene::open(SearchIndexer::getIndexDirectory());
这是seachIndexer代码:
public static function setIndexDirectory($directory){
if(!is_dir($directory)) {
throw new Exception('Directory for SearchIndexer is invalid ('. $directory .')');
}
self::$_indexDirectory = $directory;
}
public static function getIndexDirectory(){
return self::$_indexDirectory;
}
this paragraph is part of 'Zend Framework In Action' book.
SearchIndexer::setIndexDirectory(ROOT_DIR . '/var/search_index');
Places_Db_Table_Row_Observable::attachObserver('SearchIndexer');
As you can see, it’s simply a case of setting the directory to store the search index files
and attaching the class to the list of observers in Places_Db_Table_Row_Observable
using the name of the class.
Now I have a problem! I put this code in bootstrap file in runapp method, but it can't recognize the directory that I set in bootstrap!
It shows me this error
An error occurred exception 'Zend_Search_Exception' with message 'No index directory specified' in E:\xampp\php\PEAR\Zend\Search\Lucene.php:497
=======================================================
other type of my question :
I have this code in bootstrap file (runApp method):
SearchIndexer::setIndexDirectory(ROOT_DIR.'/var/search_index');
Places_Db_Table_Row_Observable::attachObserver('SearchIndexer');
I set search directory path in SearchIndexer class, but there is a prob!
When I use of below code in controller action, it can't recognize the directory that I set in bootstrap!
controller code :
$index = Places_Search_Lucene::open(SearchIndexer::getIndexDirectory());
this is seachIndexer code :
public static function setIndexDirectory($directory){
if(!is_dir($directory)) {
throw new Exception('Directory for SearchIndexer is invalid ('. $directory .')');
}
self::$_indexDirectory = $directory;
}
public static function getIndexDirectory(){
return self::$_indexDirectory;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
getIndexDirectory
函数不会返回路径,因此Places_Search_Lucene::open
失败。可能
setIndexDirectory
无法设置路径。对此进行一些调试。也许您在引导程序中使用该类,然后它被 zend 自动加载器加载。您在哪里执行此操作?
使用前尝试手动加载类:
zend loader 的文档: http:// /framework.zend.com/manual/en/zend.loader.load.html
Your
getIndexDirectory
function does not return a path soPlaces_Search_Lucene::open
fails.Maybe
setIndexDirectory
fails to set the path. Do some debugging on that.Maybe you use the class in your bootstrap before it gets loaded by zend autoloader. Where do you perform this?
Try to load the class manually before usage:
Documentation on zend loader: http://framework.zend.com/manual/en/zend.loader.load.html