How to get node_id when extending XenForo_ControllerPublic_Abstract

AndyB

Well-known member
In my add-on Similar Threads, I would like to get the node_id when a user is creating a thread.

Currently I'm able to get the thread title (what the user types into the input box) with the following code:

PHP:
$newTitle = $this->_request->getParam('title');

however when I try to get the node_id this code doesn't work:

PHP:
$currentNodeId = $this->_request->getParam('node_id');

Thank you.
 
You should always extend specific controllers unless you are creating your own route and everything.
 
You should always extend specific controllers unless you are creating your own route and everything.

In this case I'm creating my own route which is used for the AJAX to function. Does this mean that extending the ControllerPublic_Abstract in this case is correct?
 
In this case I'm creating my own route which is used for the AJAX to function. Does this mean that extending the ControllerPublic_Abstract in this case is correct?
Want to get node_id you can extends ControllerPublic_Forum to get that. In case AJAX you can put url: `forums/your-action`
 
Want to get node_id you can extends ControllerPublic_Forum to get that. In case AJAX you can put url: `forums/your-action`

Hi Nobita.Kun,

Thank you very much for explaining that I should have extended the ControllerPublic_Forum. I have now made the code changes and everything still works great. However I'm not able to get the node_id. I would assume the following code would work, but it does not.

PHP:
<?php
 
class Andy_SimilarThreads_ControllerPublic_Forum extends XenForo_ControllerPublic_Forum
{
	public function actionIndex()
	{        
		// call parent function
		parent::actionIndex();
		
		$forumId = $this->_input->filterSingle('node_id', XenForo_Input::UINT);
...
?>
 
Hi Nobita.Kun,

Thank you for your help in this thread. I ended up extending the XenForo_ControllerPublic_Forum and using the actionIndex. The reason is if I use any other action besides actionIndex the AJAX would stops working.

I was never able to get the node_id even after extending XenForo_ControllerPublic_Forum. However I think that extending XenForo_ControllerPublic_Forum is better than extending XenForo_ControllerPublic_Abstract.
 
PHP:
<?php

class Andy_SimilarThreads_ControllerPublic_Forum extends XenForo_ControllerPublic_Forum
{
    public function actionIndex()
    {     
        // call parent function
        parent::actionIndex();
     
        $forumId = $this->_input->filterSingle('node_id', XenForo_Input::UINT);
...
?>

Why are you extending XenForo_ControllerPublic_Forum, you should do this via XFCP_ and code event listener (load_class_controller) so it will work
 
Last edited:
Hi Milano,

Thank you for your assistance.

I changed my code to the following:

PHP:
class Andy_SimilarThreads_ControllerPublic_Forum extends XFCP_Andy_SimilarThreads_ControllerPublic_Forum
{
    public function actionIndex()
    {
...

I created the Code Event Listener and updated my Listener.php file. However when I try to create a new thread, type something into the title input I get the following error:

An exception occurred: Cannot load class using XFCP. Load the class using the correct loader first. in /home/southbay/www/forums/library/XenForo/Autoloader.php on line 108
 
Listener.php

PHP:
<?php

class Andy_SimilarThreads_Listener
{
	public static function Thread($class, array &$extend)
	{
		$extend[] = 'Andy_SimilarThreads_ControllerPublic_Thread';
	}	
	
	public static function Forum($class, array &$extend)
	{
		$extend[] = 'Andy_SimilarThreads_ControllerPublic_Forum';
	}	
}

?>
 
Listener.php

PHP:
<?php

class Andy_SimilarThreads_Listener
{
    public static function Thread($class, array &$extend)
    {
        $extend[] = 'Andy_SimilarThreads_ControllerPublic_Thread';
    }   
   
    public static function Forum($class, array &$extend)
    {
        $extend[] = 'Andy_SimilarThreads_ControllerPublic_Forum';
    }   
}

?>
Why not merge two controllers into a function?
if(condition1)
{
exe1
}else if(conditions2) {
exe2
}
?
 
Why not merge two controllers into a function?
if(condition1)
{
exe1
}else if(conditions2) {
exe2
}
?

Because he's using Event Hint
BTW @AndyB did you check your Event Hint class name? In this case it should be XenForo_ControllerPublic_Thread and XenForo_ControllerPublic_Forum
 
Top Bottom