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

How do i replace existing php code in a new addon?

otto

Well-known member
#1
Hello,

i have made a litle guide to sort RM items alphabetical. You can see this here:

http://xenforo.com/community/resources/rm-sort-items-alphabetical-in-resource-manager.3325/

i mean this part of my guide above:

File changes

1. open:
Code:
library/XenResource/ControllerPublic/Resource.php
  • Search in lines 331 / 332:
    PHP:
            $defaultOrder = 'last_update';
            $defaultOrderDirection = 'desc';
  • Replace:
    PHP:
            $defaultOrder = 'title';
            $defaultOrderDirection = 'asc';
    Caution! Match lines come 2 times in the file - first in line 33/34, change only the second reference!

  • Save.
Now i have made a template addon for the TMS changes and the new phrase. See packed zip attachment.



But what can i do to change the 2 lines in the resource.php (see the linked guide) from the xenforo RM ?

Can any one help?
 

Attachments

Jeff Berry

Well-known member
#2
You won't be able to extend/override those variables in that controller function, unfortunately there's just no way to do that.

What you'll need to do is try to extend the _preDispatch() method of the Resource controller (XenResource_ControllerPublic_Resource) and forge what would normally be the user supplied order params from the URL (?order=xxx&direction=ASC).

To do this, extend the controller like so:

PHP:
class XFCP_YourAddon_XenResource_ControllerPublic_Resource extends XFCP_XenResource_ControllerPublic_Resource
{
   protected function _preDispatch($action)
    {
        parent::_preDispatch($action);

        if ($action != 'Category')
        {
            return;
        }

        if (!$this->_input->inRequest('order'))
        {
            $this->_request->setParam('order', 'title');
        }

        if (!$this->_input->inRequest('direction'))
        {
            $this->_request->setParam('direction', 'ASC');
        }
    }
}
What this is doing is injecting parameters that would normally be passed through the URL. It checks to see if the user is passing these through the URL first, and if not it injects them. It will only take effect on the Category action (actionCategory method in the controller).

Good luck.