Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
import() for app vendor directory
  • I'm not sure if this is a bug or I'm going the wrong way about doing this. I've added a third party lib to my app vendor directory and after looking at how the core imports vendor libs using import function
    import('phpquickprofiler/phpquickprofiler', 'vendor');
    
    I tried the same from a class within the app but got the following error: failed to open stream: No such file or directory in COREPATH/base.php @ line 25 After looking at the function
    if ( ! function_exists('import'))
    {
     function import($path, $folder = 'classes')
     {
      $path = str_replace('/', DIRECTORY_SEPARATOR, $path);
      require_once COREPATH.$folder.DIRECTORY_SEPARATOR.$path.'.php';
    
      if (is_file(APPPATH.$folder.DIRECTORY_SEPARATOR.$path.'.php'))
      {
       require_once APPPATH.$folder.DIRECTORY_SEPARATOR.$path.'.php';
      }
     }
    }
    
    I can see why it was failing, shouldn't the function be
    if ( ! function_exists('import'))
    {
     function import($path, $folder = 'classes')
     {
      $path = str_replace('/', DIRECTORY_SEPARATOR, $path);
      
      if (is_file(COREPATH.$folder.DIRECTORY_SEPARATOR.$path.'.php'))
      {
       require_once COREPATH.$folder.DIRECTORY_SEPARATOR.$path.'.php';
      }
                    elseif (is_file(APPPATH.$folder.DIRECTORY_SEPARATOR.$path.'.php'))
      {
       require_once APPPATH.$folder.DIRECTORY_SEPARATOR.$path.'.php';
      }
     }
    }
    
    or am I going about importing third party vendor libs the wrong way? Thanks for any advice
    Dave Update: Sorry about the smiley faces the code formatting doesn't seem to do anything just # in browser
  • Use code bbcode tags for your code examples. You have to type them in, the button's don't work for some reason. The import() function was originally designed to load core vendor classes, and allow them to be extended in app. It currently has no direct support for app/vendor. Please create a feature request on http://github.com/fuel/core/issues so this can be addressed.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion