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

Which Controller to extend in lieu of XenForo_Abstract

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

  1. AndyB

    AndyB Well-Known Member

  2. Chris D

    Chris D XenForo Developer Staff Member

    I can't see anything wrong with your code.

    It's simple. There's two options:

    1) Create a new route and create a new controller that extends XenForo_ControllerPublic_Abstract

    If your board URL is http://xenforo.com/community and your new route is showdeleted, your URL will be http://xenforo.com/community/showdeleted.

    2) Extend an existing controller using the XenForo Class Proxy system and load_class_controller code event.
    PHP:
    <?php

    class Your_Controller_Name extends XFCP_Your_Controller_Name
    This allows you to either modify existing actions within that controller or add new actions to the controller.

    If your board URL is http://xenforo.com/community and you are extending the forum controller, and you're adding a new action called actionShowDeleted then your URL will be http://xenforo.com/community/forums/forum-name.1/show-deleted
     
  3. AndyB

    AndyB Well-Known Member

    Thank you, Chris.

    So if I understand correctly, I should be able to extend XenForo_Abstract class as a XFCP?

    PHP:
    <?php

    class Andy_ShowDeleted_ControllerPublic_ShowDeleted extends XFCP_XenForo_ControllerPublic_Abstract
    ...
     
  4. Marcus

    Marcus Well-Known Member

    class Andy_ShowDeleted_ControllerPublic_ShowDeleted extends XFCP_Andy_ShowDeleted_ControllerPublic_ShowDeleted
     
  5. Chris D

    Chris D XenForo Developer Staff Member

    What I'm trying to say, Andy, is your current code is fine. There should be no reason to change it.
     
  6. AndyB

    AndyB Well-Known Member

    Hi Marcus,

    When I try that I get the following error:

    Listener.php

    PHP:
    <?php

    class Andy_ShowDeleted_Listener
    {
        public static function 
    showDeleted($class, array &$extend)
        {
            
    $extend[] = 'Andy_ShowDeleted_ControllerPublic_ShowDeleted';
        }
       
        public static function 
    loadClassModel($class, array &$extend)
        {
            
    $extend[] = 'Andy_ShowDeleted_Model_DeletionLog';
        }   
    }

    ?>
    The Code Event Listener:

    pic001.jpg

    ShowDeleted.php

    PHP:
    <?php

    class Andy_ShowDeleted_ControllerPublic_ShowDeleted extends XFCP_Andy_ShowDeleted_ControllerPublic_ShowDeleted
    {    
        public function 
    actionIndex()
        {    
    ...
     
  7. AndyB

    AndyB Well-Known Member

    It's looking that way. So in this situation not using XFCP is fine?
     
  8. Chris D

    Chris D XenForo Developer Staff Member

    Yeah. But the key thing is, do you understand why?

     
  9. AndyB

    AndyB Well-Known Member

    You are reading my mind. :)

    If I were to guess it has something to do with this add-on not extending any existing class that another add-on might also be extending.
     
  10. Daniel Hood

    Daniel Hood Well-Known Member

    Extending default XenForo files = use Proxy System
    Making new files (custom datawriter, model, controller) = don't
     
  11. AndyB

    AndyB Well-Known Member

    Thank you, Daniel.

    It's wonderful when things are explained. Now it makes perfect sense.
     

Share This Page