XF 2.2 Help with extending Thread controller (Public)

RisteDimitrievski

Active member
PHP:
class Thread extends XFCP_Thread{
    public function actionAddReply(ParameterBag $params)
    {
        //$this->assertPostOnly();//
        $param = parent::actionAddReply($params);
        $visitor = \XF::visitor();
        $user = $visitor->user_id;
        $threadid = $param->thread_id;
        $topic = $this->assertViewableThread($threadid, ['Watch|' . $visitor->user_id]);
        $thread = \XF::finder('pointssystem:Node')->where('node_id','=',$topic->node_id)->fetchOne();
        $threadpoints = $thread['points'];
        $users = \XF::finder('pointssystem:User')->where('user_id','=',$user)->fetchOne();
        $userpoints = $users['points'] + $threadpoints;
        $users->points = $userpoints;
        $users->save();
        return $param;
    }
}

I get:
ErrorException: [E_NOTICE] Undefined property: XF\Mvc\Reply\View::$thread_id in src\addons\pointssystem\XF\Pub\Controller\Thread.php at line 28

What might cause this ??

This line in my code on line 28:
PHP:
$threadid = $param->thread_id;
 

forumSolution

New member
PHP:
class Thread extends XFCP_Thread{
    public function actionAddReply(ParameterBag $params)
    {
        //$this->assertPostOnly();//
        $param = parent::actionAddReply($params);
        $visitor = \XF::visitor();
        $user = $visitor->user_id;
        $threadid = $param->thread_id;
        $topic = $this->assertViewableThread($threadid, ['Watch|' . $visitor->user_id]);
        $thread = \XF::finder('pointssystem:Node')->where('node_id','=',$topic->node_id)->fetchOne();
        $threadpoints = $thread['points'];
        $users = \XF::finder('pointssystem:User')->where('user_id','=',$user)->fetchOne();
        $userpoints = $users['points'] + $threadpoints;
        $users->points = $userpoints;
        $users->save();
        return $param;
    }
}

I get:


What might cause this ??

This line in my code on line 28:
PHP:
$threadid = $param->thread_id;
According to your code, you are getting

PHP:
$threadid = $param->thread_id;

from parent function so it should be like this

PHP:
$threadid = $param->getParam('thread_id');
 
Last edited:
Top