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

What is the best way to alter simple functionality in a large method?

#1
In this case, I'm working with the XenForo_ControllerPublic_Forum::actionForum() method. All I need to do is change this line:

PHP:
$threadsPerPage = XenForo_Application::get('options')->discussionsPerPage;
and replace it with my own bit of code. What is the best way to do this? I know I could just copy the entire method into my extension method, but that is awfully hacky and a short term solution. If you had to change that line in the actionForum method, how would you go about it?
 

Chris D

XenForo developer
Staff member
#2
You can temporarily override option values at run time:
PHP:
XenForo_Application::getOptions()->set('discussionsPerPage', 999);
So you would just extend the class, and set the value before returning the parent:

PHP:
public function actionForum()
{
    XenForo_Application::getOptions()->set('discussionsPerPage', 999);

    return parent::actionForum();
}
 
#3
Boom. That's exactly what I was wanting to do, but I didn't mention it because I thought it might be the wrong way to go about it and didn't want to look stupid :)

Thanks Chris!