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

Extending member controller but no more profiles

Discussion in 'XenForo Development Discussions' started by account8226, Dec 30, 2012.

  1. account8226

    account8226 Guest

    Hello,

    I am following this tutorial by Kier, to extend member's controller (each member have to have a new custom page, that they can access via their profile url/newpagetesting for example).

    So http://forum/members/1/newpagetesting would bring to the new page (empty for the moment) and http://forum/members/1/ would bring anyone to the normal profile from the xenforo core.

    My problem is that when I want to load the normal profile, it brings me to the extended class I made, with the empty template.

    I have my Public controller :
    PHP:
    <?php
    class A_ControllerPublic_Test
        
    {
            public function 
    actionIndex()
            {
                
    $userId $this->_input->filterSingle('user_id'XenForo_Input::UINT);
                
    $user $this->getHelper('UserProfile')->assertUserProfileValidAndViewable($userId);
     
                return 
    $this->responseView(
                    
    'Dev_ViewPublic_Member_Title''custom_profile',
                    array(
    'user' => $user)
                );
            }
        }
    ?>
    And here is my LoadClassController :
    PHP:
    <?php
    class A_Listener_LoadClassController
    {
        public static function 
    extendMemberController($class, array &$extend)
        {
            if (
    $class == 'XenForo_ControllerPublic_Member')
            {
                
    $extend[] = 'A_ControllerPublic_Test';
            }
        }
    }
    I created the listener.

    Best regards.
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    You need to use the XFCP class:

    Code:
    <?php
    class A_ControllerPublic_Test extends XFCP_A_ControllerPublic_Test
        {
            public function actionIndex()
            {
                $userId = $this->_input->filterSingle('user_id', XenForo_Input::UINT);
                $user = $this->getHelper('UserProfile')->assertUserProfileValidAndViewable($userId);
     
                return $this->responseView(
                    'Dev_ViewPublic_Member_Title', 'custom_profile',
                    array('user' => $user)
                );
            }
        }
    ?>
    
    And note that you are overriding the existing actionIndex() with your extended class. That will replace the member list. Kier's example was to create a new action that doesn't already exist. You can do either, I just question your decision to override actionIndex().
     
    account8226 likes this.
  3. account8226

    account8226 Guest

    Thanks for the awnser Jake, I was stupidly overwritting the index action, just had to create an other action called title, and everything is working then ;)

    Really appreciate your help.
     

Share This Page