How Can I Modify a Line in a ControllerPublic File

DrYontem

Well-known member
Hi All,

I want to modify a line in a ControllerPublic_X file using via listener
How can i do that?

for example (that's not mine problem, it is just for example)
XenForo_ControllerPublic_Member::actionIndex

original line
PHP:
$latestUsers = $userModel->getLatestUsers($criteria, array('limit' => 8));

i want to modify like that
PHP:
$latestUsers = $userModel->getLatestUsers($criteria, array('limit' => 100));

that is just example

regards...
 
With a listener you can extend the entire actionIndex(). That allows you to execute code before or after the original is called. For example, your extended function could call the parent and then afterwards replace the 'latestUsers' param in the response, querying again the latest members.

Create a listener for load_class_controller to extend the class. Here is a code example of an extended controller:

http://xenforo.com/community/thread...-without-adding-a-template.38684/#post-427497

You can run the parent function, capture the response, do your own stuff, then return the original response (or modified response).
 
You are basically trying to do what one of my add-ons does.

There are much better ways of doing it, but I basically modified the parameter and requeried with my desired criteria. I should have also extended the view instead of the controller too...


But you can see how I did it in my add-on. It's one way but not the best or only way:

http://xenforo.com/community/resources/increase-newest-highest-posting-users.1374/

EDIT: Nice ninja :)
 
thanks for your answer Jake and Chris =)
but, it doesnt work for me
maybe i couldnt explain myself clearly, sorry =(

i need give an another example
XenForo_ControllerPublic_Thread::actionAddReply
line 490 (original file)
PHP:
$writer->set('user_id', $visitor['user_id']);

i need
PHP:
$writer->set('user_id', 761);

if i use response, $writer will read the original code and and of course will save it
and will read my modified code after saving (i tried and it works like that)

i want to modify line 490 before using dw save function
 
You would probably need to actually make this change in the DataWriter, rather than the Controller.

The DataWriter has a function called preSave that you can extend.

In there you'd be able to do something like:

PHP:
$this->set('user_id', 761);
 
The system functions based on extended classes, not directly changing existing code. You could make it so your extended function does not even call the parent, thereby allowing you to copy/paste the entire function into your extended class with the small code change.
 
The system functions based on extended classes, not directly changing existing code. You could make it so your extended function does not even call the parent, thereby allowing you to copy/paste the entire function into your extended class with the small code change.
my first try was copy/paste function with small code change and it worked
but i have a question for about extend a functions all codes


example
there is 1 line changing in my extended (so edited) class
the 1 line is using $writer

and u wrote another add-on
your add-on wants extend the same file (calling parent)

will there any crash between your add-on and my add-on

ps: i am sorry due to my English, i need practice but i have to time and teacher :(
 
Back
Top Bottom