Magento Observer not doing much observing
So this is my first module, so I figured there would be errors. But I am stuck and thought the intelligence of the stack overflow community could help out.
Essentially I want my module to listen for the event of a catalog search index update and perform some code based on that.
So I told magento to recognize my module in:开发者_运维问答
app/etc/modules/Nate_SearchToFind.xml
<?xml version="1.0"?>
<config>
<modules>
<Nate_SearchToFind>
<active>true</active>
<codePool>local</codePool>
</Nate_SearchToFind>
</modules>
</config>
Then in: 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>
Then in: 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
}
}
Does anyone spot some errors in my code (I'm sure they are in there) or as my approach as a whole, but I cannot seem to find them...Thanks for the help!
Your observer class name is wrong. It should be Nate_SearchToFind_Model_Observer
in the PHP class file and the XML observer section.
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.
精彩评论