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

I would like to extend FindNew

Discussion in 'XenForo Development Discussions' started by AndyB, Sep 23, 2014.

  1. AndyB

    AndyB Well-Known Member

    I would like to extend FindNew, but I cannot seam to pass the variable to the find_new_posts template.

    What is incorrect with this PHP code?

    PHP:
    <?php

    class Andy_ShowModeration_ControllerPublic_FindNew extends XFCP_Andy_ShowModeration_ControllerPublic_FindNew
    {
        public function 
    actionPosts()
        {
            
    // get parent        
            
    $parent parent::actionPosts();
            
            
    // declare variable
            
    $showModeration 0;
            
            
    // get cookie
            
    $showModeration XenForo_Helper_Cookie::getCookie('show_moderation');

            
    // set params
            
    $parent->params['showModeration'] = $showModeration;            

            
    // return parent
            
    return $parent;        
        }
    }
    Thank you.
     
  2. Nobita.Kun

    Nobita.Kun Well-Known Member

    FindNew controller using $subView so you must assign your params into subView. :D
     
    AndyB likes this.
  3. AndyB

    AndyB Well-Known Member

    I was thinking this had something to do with subView.

    Unfortunately I don't have any experience with subView or how to assign a variable to it. Would you or someone be so kind as to show what needs to be done, or do you need more information from me?
     
  4. Nobita.Kun

    Nobita.Kun Well-Known Member

    PHP:
    if (!empty($parent->subView)
        && 
    $parent->subView instanceof XenForo_ControllerResponse_View
    )
    {
        
    $subParams $parent->subView->params;

        
    // Your code!
    }
    Maybe that's help to you :)
     
    AndyB likes this.
  5. AndyB

    AndyB Well-Known Member

    Hi Nobita.Kun,

    Thank you so much for helping.

    This PHP code works perfect!

    PHP:
    <?php

    class Andy_ShowModeration_ControllerPublic_FindNew extends XFCP_Andy_ShowModeration_ControllerPublic_FindNew
    {
        public function 
    actionPosts()
        {
            
    // get parent        
            
    $parent parent::actionPosts();        
            
            
    // continue if subView
            
    if (!empty($parent->subView) && $parent->subView instanceof XenForo_ControllerResponse_View)
            {
                
    // get subParams
                
    $subParams $parent->subView->params;
                
                
    // declare variable
                
    $showModeration 0;
                
                
    // get cookie
                
    $showModeration XenForo_Helper_Cookie::getCookie('show_moderation');
        
                
    // set params
                
    $parent->subView->params['showModeration'] = $showModeration;    
            }
            
            
    // return parent
            
    return $parent;            
        }
    }
     
    Last edited: Sep 23, 2014
    Nobita.Kun likes this.
  6. Jeff Berry

    Jeff Berry Well-Known Member

    Just to elaborate on @Nobita.Kun already correct answer about the subview: the subview is the same thing as the main view, it's just nested inside another view. It can be worked with the same way a normal view can.

    With your code block, I notice two things:

    PHP:
    // get subParams
    $subParams $parent->subView->params;
    This line is not necessary, as you are interested in setting the sub parameters, not getting them. Also, you don't use this variable in your script, so there's no reason to have it.

    PHP:
    // declare variable
    $showModeration 0;
    This line is also not necessary. You must have a coding background in a different language? :p In PHP you do not need to declare your variables. Your next line immediately assigns the variable a value from your cookie - making this line have no effect.

    This is your effective code:
    PHP:
    class Andy_ShowModeration_ControllerPublic_FindNew extends XFCP_Andy_ShowModeration_ControllerPublic_FindNew
    {
        public function 
    actionPosts()
        {
            
    // get parent
            
    $parent parent::actionPosts();
            
    // continue if subView
            
    if (!empty($parent->subView) && $parent->subView instanceof XenForo_ControllerResponse_View) {
                
    // get cookie
                
    $showModeration XenForo_Helper_Cookie::getCookie('show_moderation');
                
    // set params
                
    $parent->subView->params['showModeration'] = $showModeration;
            }

            
    // return parent
            
    return $parent;
        }
    }
     
    AndyB and Chris D like this.
  7. AndyB

    AndyB Well-Known Member

    Hi Jeff,

    Thank you kindly for taking the time to improve my code and to educate me, I really appreciate it. :)
     
    Jeff Berry and Nasr like this.

Share This Page