All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Loading a model for third_party_search_index

Derek 20 Nov 2013 23:42 question, complete

Hey Low - having an issue with a custom fieldtype I've developed for a client and the third_party_search_index method.

My fieldtype stores simple codes, which relate to descriptions of those codes stored in the db. My add-on has a data model which fetches/caches/returns the descriptions for each code.

I'm using this model in the other fieldtype methods (display, replace, etc) successfully - loading it via the fieldtype constrictor - but when Low Search goes to index a field, it hits a wall with "cannot load model".

I tried moving the loading of the model directly into third_party_search_index; then adding a manual add_package_path; then including the model class directly and instantiating it - all fail with the same error.

This was happening with 2.4.3, and now with 3.0 as well - both under EE 2.7.2.

Is there something unique in how Low Search calls the indexing method which prevents a fieldtype's model from loading?

Replies

  1. Low 21 Nov 2013 08:19

    Just tried this with Low Events (added a third_party_search_index method to it), which loads its own model in the constructor... Worked as planned. Is it a php exception that is thrown, or is it an EE/CI error message? Also, what's your PHP version?

  2. Derek 21 Nov 2013 20:24

    This is what I see in the console after firing the AJAX call to rebuild the index:


    [Error] Failed to load resource: the server responded with a status of 500 (Internal Server Error) (admin.php, line 0)
    [Error] Internal Server Error,{"error":" Unable to locate the model you have specified: onix_data_model"}
    (anonymous function) (admin.php, line 388)
    (anonymous function) (admin.php, line 360)




    PHP is 5.3.10.

  3. Low 22 Nov 2013 09:10

    If you right-click and open link in new tab/window the Rebuild Index link, you'll be able to see the error as it would be thrown without Ajax. What does that say?

  4. Derek 22 Nov 2013 13:53

    That gives me one of these guys:



    An Error Was Encountered
    Unable to locate the model you have specified: onix_data_model

  5. Low 22 Nov 2013 13:57

    Okay, so that's generated by /system/codeigniter/system/core/Loader.php#232, the model() method.

    You said you already tried to add the package path. What happens when you output print_r($this->_ci_model_paths); above that line?

  6. Low 22 Nov 2013 14:00

    I can also take a look myself, but I'd need both SuperAdmin and FTP logins.

  7. Derek 22 Nov 2013 14:11

    Thanks Low - your print_r($this->_ci_model_paths) debugging trick helped me sort it out. Without calling add_package_path, my add-on was not in the array of paths (just 3 entries for Low Search, and one for Low Variables).

    add_package_path('onix_data') didn't work either - it simply added 'onix_data' as a path in the array, with no root path behind it).

    add_package_path(PATH_THIRD.'onix_data') did the trick, and resolved the errors.

    I won't pretend to understand why manually adding of the path would be necessary in the third_party_search_index method, but not in any of the other methods in the same class.

    Thanks for the great support.

  8. Low 22 Nov 2013 14:14

    Heh, well, EE's package handling methods aren't optimal, that's for sure.

    As a rule of thumb, I tend to always use ee()->load->add_package_path(PATH_THIRD.'my_package'); which seems to work for me.