about the new markThreadRead()

DarkSign

Active member
Hello devs.

I was testing my add-on, the Auto Lock Threads, in the new XenForo, and then it gave me this error:

Argument 4 passed to XenForo_Model_Thread::markThreadRead() must be an array, integer given, called in C:\apache\htdocs\XenForo\library\DS\AutoLockThreads\ControllerPublic\AutoLockThreads.php on line 77 and defined

This is how I am trying to get the userID and pass to the markThreadRead() method:


PHP:
//just the relevant part of the code
 
$visitorId = XenForo_Visitor::getUserId();
 
//after some more lines
 
$this->_getThreadModel()->markThreadRead($thread, $forum, XenForo_Application::$time, $visitorId);


So, for the message, the method requires an array. I will study the new core code later, when I have time, but I need a fix for that, so can someone explain how can I get the Argument 4 (the user id, in previous version) correctly?
 
the 4th argument needs the entire viewing user array not just the ID...

do this instead..

PHP:
//just the relevant part of the code
 
$visitor = XenForo_Visitor::getInstance();
 
//after some more lines
 
$this->_getThreadModel()->markThreadRead($thread, $forum, XenForo_Application::$time, $visitor);
 
I tested it, but it seems to be returning an Object and not an Array.

the following error:

Argument 4 passed to XenForo_Model_Thread::markThreadRead() must be an array, object given, called in C:\apache\htdocs\XenForo\library\DS\AutoLockThreads\ControllerPublic\AutoLockThreads.php on line 83 and defined

Also, to keep things up with the $visitor object, how do I extract the ID, that is being used by other calls, and those are working?
 
ah ya, this should do the trick for you.

$viewingUser = XenForo_Visitor::getInstance()->toArray();

$viewingUser['user_id']; is the view users user ID.

Do a Zend_Debug::dump(); to see everything within the object or array.
 
And now that solved this small issue with my code. It's working on 1.1! I will update the resource now, thank you very much for now :)
 
Top Bottom