1

所以这是我的第一个模块,所以我认为会有错误。但我被困住了,认为堆栈溢出社区的智能可以提供帮助。

本质上,我希望我的模块监听目录搜索索引更新的事件并基于此执行一些代码。

所以我告诉 magento 识别我的模块:

应用程序/etc/modules/Nate_SearchToFind.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Nate_SearchToFind>
            <active>true</active>
            <codePool>local</codePool>
        </Nate_SearchToFind>
    </modules>
</config> 

然后在:app/local/Nate/SearchToFind/etc/config.xml

<?xml version="1.0"?>
<config>
  <global>
    <models>
        <natesearchtofindbundle>
             <class>Nate_SearchToFind_Bundle_Model</class>
        </natesearchtofindbundle>
    </models>
    <events>
        <catalogindex_plain_reindex_after>
            <observers>
                 <Nate_SearchToFind_Observer>
                     <type>singleton</type>
                     <class>Nate_SearchToFind_Bundle_Model_Observer</class>
                     <method>beautify_search</method>
                 </Nate_SearchToFind_Observer>
             </observers>
        </catalogindex_plain_reindex_after>
    </events>
  </global>
</config>

然后在:app/code/local/Nate/SearchToFind/Model/Observer.php

<?php
class Nate_SearchToFind_Bundle_Model_Observer
{
    public function __construct()
    {
    }
    public function beautify_search($observer)
    {
        //perform function operations here
    }
}

有没有人在我的代码中发现一些错误(我确定它们在那里)或者作为我的整体方法,但我似乎找不到它们......感谢您的帮助!

4

1 回答 1

4

您的观察者类名称错误。它应该Nate_SearchToFind_Model_Observer在 PHP 类文件和 XML 观察者部分。

Class names in the Zend Framework follow the directory structure. The class prefix you are trying to use, Nate_SearchToFind_Bundle_Model, actually refers to files in app/code/{core,local,community}/Nate/SearchToFind/Bundle/Model, I believe. It needs to be changed to Nate_SearchToFind_Model to reflect your current directory structure.

You're also defining the class prefix, but not using it. For example, the <class></class> section of the observer section could read <class>natesearchtofindbundle/observer</class>, which would map to Nate_SearchToFind_Model_Observer, assuming you aligned the prefix with your directory structure.

于 2011-08-11T07:09:22.967 回答