在引导程序中设置静态方法的默认值

发布于 2024-11-03 10:59:28 字数 1424 浏览 2 评论 0原文

本段是“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

日暮斜阳 2024-11-10 10:59:28

您的 getIndexDirectory 函数不会返回路径,因此 Places_Search_Lucene::open 失败。

可能 setIndexDirectory 无法设置路径。对此进行一些调试


也许您在引导程序中使用该类,然后它被 zend 自动加载器加载。您在哪里执行此操作?

使用前尝试手动加载类:

Zend_Loader::loadClass('Path_To_SearchIndexer',
    array(
        '/home/production/mylib',
    )
);

zend loader 的文档: http:// /framework.zend.com/manual/en/zend.loader.load.html

Your getIndexDirectory function does not return a path so Places_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:

Zend_Loader::loadClass('Path_To_SearchIndexer',
    array(
        '/home/production/mylib',
    )
);

Documentation on zend loader: http://framework.zend.com/manual/en/zend.loader.load.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文