Extending a class, but only need to change one line of code

SchmitzIT

Well-known member
Hi,

I'm attempting to write an add-on that changes a single line in one of the standard XenForo files (ControllerPublic/Forum.php).

The functionality I intend to change can be altered by changing a single line. I figured the easiest would be for me to build an add-on that extends ControllerPublic_Forum. Would I need to duplicate the entire function and change the line I need to change in order to achieve what I'd need, or is there a more elegant solution that doesn't involve copying a lot of code that just repeats what was already there?

Thanks!

/Peter
 
It's difficult to say without knowing the line of code you want to change and how.

There's different ways of doing things in certain circumstances.
 
It's this bit here:

Code:
public function actionForum()
    {
       ...
       $threadsPerPage = XenForo_Application::get('options')->discussionsPerPage;
      ...
   }
 
If I were you, I would setup a listener for front_controller_pre_dispatch and do:

PHP:
public static function frontControllerPreDispatch() {
    $options = XenForo_Application::get('options');
    $options->set('discussionsPerPage', 999999);
}

You can wrap it in a conditional if you only want to change it under certain conditions, it will overwrite the set option.
 
Sorry, forgot to come back and reply :)

Jeremy's solution looks to be the one.

The only other way is to modify the viewParams in the controller but it means duplicating the query to get the correct number of discussions etc and then replacing the existing params with the updated ones. It's quite messy, actually, because you might need to still reproduce a fair bit of the code to achieve it. Sometimes that would be ok, but in this case, Jeremy's looks like it should be perfect.
 
Top Bottom