Jump to content

Autoload CLASS by Plugin method ..


Recommended Posts


    reading the instructions I see :-



Method 2 - from a single class file:
Alternatively it is possible to create a custom class for your code in the classes folder with the same name as the value of the GET variable "_a". For example "classes/news.class.php". If this class exists and the method within the class has been initiated it is possible to work this way. CubeCart has a class autoloader system in that it will automatically load any class file in the classes folder with the naming convention *.class.php. 

This is good and in principle would simplify things especially because of the autoload.


However, the implication is that the plugin's class file then has to be loaded from the cubecart/classes folder, which would make distribution difficult ?


Or, am I somehow wrong 🙃.


Many Thanks, Chris Coleman.




Link to comment
Share on other sites

When CubeCart starts up, eventually the HookLoader class is instantiated. During this class's construction, a call is made to build a "hooks list". The source of data for this list is the database table CubeCart_hooks. The table CubeCart_hooks is populated with references to a plugin's hooks when that plugin is installed and enabled.

For every record in the table CubeCart_hooks, the plugin's filename is used in a path, such as "CC_ROOT_DIR/modules/plugins/plugin_filename", and then that path is added to PHP's 'include_path', as well as CubeCart's internal list of paths. (You can examine the current 'include_path' in admin, PHP Info, in the Core table. The 'include_path' is a list of all file paths that PHP will look into for a given file.)

Up to this point, to get the AutoLoader to locate and register a class, that class must be in the /classes/ folder (as the default location), and the main folder of enabled plugins. (Other modules, such as Shipping and Gateway, are understood to have a required class in their main folder, and it will get registered as needed.)

There are plugins that have their own classes in their /classes/ folder. To get these classes registered, the plugin uses a hook that is available near the end of CubeCart's wake-up sequence, 'controller.index', just before CubeCart starts fetching data to populate and display the intended page. (There are earlier hooks available, however.)

The AutoLoader class has a static function appendPaths($path) that can be used to add to CubeCart's list of paths to look in for a requested class. CubeCart's list of paths may have more entries than PHP's 'include_path' value.


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...