Difficulty with third party library

edited September 2013 in News & Announcements
I'm trying to use a third party library to detect mobile devices and libraries. http://mobiledetect.net
I downloaded it, and after I failed to get it to load, I renamed the file to Mobile_detect.php and the class to Mobile_detect to ensure that I was not violating a Fuel naming convention, but to no avail. (I've also tried keeping the original capitalization and accessing it based on a Codeigniter example that supposedly works).
It is in application/third_party since it was apparent that Fuel was looking there (I had tried it in application/libraries first to no avail)

I'm trying to access it from the application/views/_variables/global.php via
$CI =& get_instance(); $CI->load->library('Mobile_detect'); $detect = new $CI->mobile_detect(); if ($detect->isMobile() ) {$vars['is_mobile'] = true; $vars['is_computer'] = false; } if ($detect->isTablet() ) {$vars['is_tablet'] = true; $vars['is_computer'] = false; }

The error appears to be on
$CI->load->library('Mobile_detect');

and the error is
Fatal error: Cannot access empty property in /home4/fnpsdevo/public_html/fuel/application/third_party/fuel/Loader.php on line 215

and line 215 is
return CI::$APP->$_alias;

Any clues?

Comments

  • edited 11:26AM
    Does it work if you just put it in your libraries folder?

    You may need to add the package path if you are using the third_party directory.
    http://ellislab.com/codeigniter/user-guide/libraries/loader.html
  • edited 11:26AM
    Nope -- so, I ran a test --- I tried to load a library (in libraries) that I know is good (Fuel's Validator). Same error. In libraries, I also get another error first

    Severity: Notice
    Message: Undefined index: Validator
    Filename: fuel/Loader.php
    Line Number: 206

    And then

    Fatal error: Cannot access empty property in /home4/fnpsdevo/public_html/fuel/application/third_party/fuel/Loader.php on line 215

    I think this must have something to do with my trying to load it from
    application/views/_variables/global.php
    and not from a controller

    Thanks
  • edited 11:26AM
    I think this line is incorrect:
    $CI->load->library('Mobile_detect'); $detect = new $CI->mobile_detect();
    You want something like this:
    $CI->load->library('mobile_detect'); // I would change the casing of the class to Mobile_detect $detect = $CI->mobile_detect->getDetectionType(); // or whatever method
    The load library automatically creates a new instance and attaches it to the $CI object so you don't need to use "new".
  • edited September 2013
    That Worked! Thank you!
Sign In or Register to comment.