Try CumulusClips Cloud Hosting

Using class in a plugin

Hi,
I'm coding a plugin. which parse a csv file. It work well and know i want to use the PHPExcel library to parse others formats. But when i include the classe directory of the library, there's a php warning :
Warning: include(PHPExcel_Shared_String.php): failed to open stream: No such file or directory in /var/www/html/tutosapprentis/cc-core/lib/App.php on line 29

Warning: include(): Failed opening 'PHPExcel_Shared_String.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear:/var/www/html/tutosapprentis/cc-core/lib:/var/www/html/tutosapprentis/cc-core/models:/var/www/html/tutosapprentis/cc-core/mappers:/var/www/html/tutosapprentis/cc-core/services') in /var/www/html/tutosapprentis/cc-core/lib/App.php on line 29

I think it's a conflict between the load in app.php and the autolaoder in the library. Is it a good idea to add the path of my plugin in cc-core/system/boostrap.php after line 24 ? Or there is a better way ?

Comments

  • Can you share the high level code of your plugin, specifically where the Excel class is being included or defined?

    Where in the filesystem is the Excel class located?
  • Hi.

    Here is a screenshot of my project. I include PHPExcel in the plugin. you can see I include PHPExcel.php requires autoload.php this file construct class name with the path name. Example in the error message above "PHPExcel_Shared_String.php" string.php in the directory Share, in the PHPExcel's directory.

    You can see i I have to include the class i made '/AddUsersMapper.php', if i don't do this thing i have the same warning than above.
    bug-phpexcel-cc.jpg
    1045 x 709 - 395K
  • Please share the actual plugin. In your case it is AddUsersCsv.php.
  • you want me to share all the code? I will merge it on github, i will give the link. Meanwhile i think i had made a mistake in the abstract class for plugins, i can load class in ?
  • you can attach the file here, or post a link as you described. Whatever is easier for you. I would like to see the code in that file to see if that is causing any issues.
  • Hi.
    you can find all the plugin's code here : https://github.com/capetrel/AddUserCsv-master/blob/master/README.md

    Please be indulgent, i'm a junior developer, and i begin php since one month.

    thanks.
  • There shouldn't be a conflict as both App::loadClass() and PHPExcel_Autoloader use spl_autoload_register which allows for multiple autoload methods.

    I must admit that our autoloader is a bit weak. Let's try this, replace the current load method in the App.php class with the following code and see if that helps:

    public static function loadClass($class, $path = '')
    {
    $path .= (!empty($path)) ? '/' : '';

    if (
    !class_exists($class)
    && file_exists($path . "$class.php")
    && is_readable($path . "$class.php")
    ) {
    include($path . "$class.php");
    } else {
    return false;
    }
    }
  • Hi thanks for the answer, but it didn't work :

    Fatal error: Class 'Database' not found in /var/www/html/tutosapprentis/cc-core/system/bootstrap.php on line 37.

    because of the 'file_exists' and 'is_readable'.
  • One of my teacher tell me to call the $includePath. I will try this and tell you the result.
  • Ah yes, I see the problem. Our autoloader is not seaching the include path in the code I provided. That is why you got that error. Please stand by, we will get you the updated snippet.
  • still waiting ^^
This discussion has been closed.