FrankHe (2) [Avatar] Offline
I am following the Zend_Search to test the observer pattern used on Zend_Search. I now met a problem and don't know how to overcome, please help.

1. In controller action, I have this code:
$places = new Application_Model_DbTable_Places();
$allPlaces = $places->fetchAll();
foreach($allPlaces as $place){
$doc = Application_Model_SearchIndexer::getDocument($place);

2. In class Application_Model_SearchIndexer, I have this definition:

public static function getDocument(Application_Model_DbTable_PlacesObserverable $row)
{ .....}

3. PlacesObservable is defined as follows:
class Application_Model_DbTable_PlacesObserverable
extends Zend_Db_Table_Row_Abstract{

When I run, I got this error:

Catchable fatal error: Argument 1 passed to Application_Model_SearchIndexer::getDocument() must be an instance of Application_Model_DbTable_PlacesObserverable, instance of Zend_Db_Table_Row given,....

From this error, I can see the item type for Zend_Db_Table_Abstract::fetchAll is type of Zend_Db_Table_Row, but parameter type for getDocument() is of type of observerable, although Application_Model_DbTable_PlacesObserverable extends Zend_Db_Table_Row, if I just pass type of Zend_Db_Table_Row, it can not be converted to Application_Model_DbTable_PlacesObserverable automatically.

Actually, the paramter type for gotDocument() should be Application_Model_DbTable_Place as defined here:
class Application_Model_DbTable_Place extends Application_Model_DbTable_PlacesObserverable
{ ...}
IN which, we defined getSearchIndexFields() function.

I checked the source code of the book, and the signature for getDocuemnt is;
public static function getDocument(Places_Db_Table_Row_Observable $row)
But passed data type should be Zend_Db_Table_Row, I didn't see any place to convert the data type.

So my question is how the data type is converted from Zend_Db_Table_Row to xxxObserverable? In the book, there is NO mention for this step at all.

FrankHe (2) [Avatar] Offline
Re: Zend_Search reindex parameter type error
got it, i forgot to set the _rawClass in the class definition
Now it works fine
akrabat (479) [Avatar] Offline
Re: Zend_Search reindex parameter type error
Glad you sorted it smilie