I would like to extend FindNew

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.
 
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?
 
PHP:
if (!empty($parent->subView)
    && $parent->subView instanceof XenForo_ControllerResponse_View
)
{
    $subParams = $parent->subView->params;

    // Your code!
}
Maybe that's help to you :)
 
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:
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;
    }
}
 
Back
Top Bottom