1. 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

Discussion in 'XenForo Development Discussions' started by thorrr, Nov 5, 2013.

  1. thorrr

    thorrr Member

    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?

  2. Jeremy

    Jeremy Well-Known Member

    Does the class exist within the library directory? If not, you just need to require it as you would any normal PHP file.
  3. thorrr

    thorrr Member

    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.
  4. Jeremy

    Jeremy Well-Known Member

    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. thorrr

    thorrr Member

    Ah okay thanks, i was looking for something like that. I like that approach more than hard linking files.

Share This Page