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

about the new markThreadRead()

DarkSign

Active member
#1
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?
 

Bob

Well-known member
#2
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);
 

DarkSign

Active member
#3
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?
 

Bob

Well-known member
#4
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.
 

DarkSign

Active member
#5
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 :)