• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Best way to include an external class

#1
Hey guys, new customer here.

First off just want to say that so far developing with xF has been amazing. Everything just works, and the code is easy to follow, so i just wanted to say thanks to the dev's and keep up the good work.

Now my question..

I have some external pages that i am building, i have created routes and controllers for these, using some xF models as needed etc, all of which is working fine. What i need to do now is include an external class and have access to instantiate this class in the controller so i can get the data it is supposed to collect. What is the best way to load this class. Is there a hook somewhere where i could tell xF to load this class, or is there a specific naming structure which would autoload this class?

Thanks,
thorrr
 

Jeremy

Well-known member
#2
Does the class exist within the library directory? If not, you just need to require it as you would any normal PHP file.
 
#3
The class is located here library/addonname/class123/class.php

i currently have it required as you mentioned and it works, i was just wondering if there was a better way to go about it.
 

Jeremy

Well-known member
#4
You can just call it. XenForo has an auto loader that will include classes as needed. Just note it follows directory structure:
XenForo_ControllerPublic_Forum is found in library/XenForo/ControllerPublic/Forum.php
 
#5
You can just call it. XenForo has an auto loader that will include classes as needed. Just note it follows directory structure:
XenForo_ControllerPublic_Forum is found in library/XenForo/ControllerPublic/Forum.php
Ah okay thanks, i was looking for something like that. I like that approach more than hard linking files.