Welcome Guest, Not a member yet? Register   Sign In
Custom library causes error -
#1

[eluser]mabright[/eluser]
When ever I reference my library class, I receive an error. The error is referring to one of my models but I do not use the model in my library.

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Yelp::$Location_model

Filename: libraries/Loader.php

Line Number: 1035

Fatal error: Call to a member function _assign_libraries() on a non-object in

Yelp class:
Code:
class Yelp {
    
    var $CI;
    
    public function __construct()
    {
        $this->CI =& get_instance();
    }
    
    public function get_locations($url)
    {
        $results = $this->parse_response(file_get_contents($url, "r"));
        return $results;
    }
    
    public function build_url($search_term,$location,$categories)
    {
        $loc = str_replace(' ',' ',$location);
        
        $url  = 'http://api.yelp.com/business_review_search?term='.$search_term;
        $url .= '&location;='.$loc;
        $url .= '&limit=2&ywsid;='.$this->CI->config->item('yelp_devkey');
        $url .= '&category;='.$categories;
        return $url;
    }
    
    private function parse_response($response)
    {        
      $results = $this->__unserialize($response);
      return $results;
    }
    
    private function __unserialize($sObject)
    {
    $sObject = ereg_replace("\n", " ", $sObject);
    $sObject=htmlspecialchars_decode($sObject);
        return preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'", $sObject );
    }
    
}
#2

[eluser]vitoco[/eluser]
Dumb question , are you loading the library like ?
Code:
$this->load->library('yelp');

...
#3

[eluser]danmontgomery[/eluser]
_ci_assign_to_models gets called whenever you load a library, which assigns that library to each of your loaded models so it's accessible the same way as it is in the controller... For some reason, CI thinks you have 'location_model' loaded, but it isn't assigned to the CI superobject. Are you unsetting that model for any reason, or doing anything else strange with it?
#4

[eluser]mabright[/eluser]
I have a controller called search and I load the library like $this->load->library('Yelp');. Below is the code and I do not use the location model in this controller at all.

Code:
class Search extends Controller {

    public function __construct()
    {
        parent::Controller();        
        
        $this->load->library('input');                
        $this->load->library('form_validation');
        $this->load->library('user_agent');                            
    }
    
    public function index()
    {
        $this->get_venues();
    }

    public function get_venues()
    {
        $this->load->library('Yelp');
        $yelp_url = $this->yelp->build_url('search term','Santa Clara CA USA','restaurant');        
        $venues = $this->yelp->get_locations($yelp_url);
        $this->_display($venues);
    }
...
#5

[eluser]danmontgomery[/eluser]
Well CI thinks it's loaded...

I'd stick a call to debug_backtrace() in that model's constructor to see where it's being called
#6

[eluser]mabright[/eluser]
I'm a friggin nut cake. I originally had my Yelp class in the application/library folder and this version had reference to the model in it. I removed it locally but not from my server so both Yelp classes existed on my web server. Now it works fine.




Theme © iAndrew 2016 - Forum software by © MyBB