sonnb
Well-known member
Hello,
I'm confusing the way to add extra actions to controller.
For example, after thread was created I need to set its state.
- We could do this by rewrite the action (copy full code then edit) but by this way, our addon might conflict with other addons that also extending the controller.
- Another way is execute parent::actionAddThread(); then add our actions.
But you could see that we only are to get threadId by search thread id from redirectTarget since the parent controller return XenForo_ControllerResponse_Redirect.
Is this an good way to do? Do you have any better way to perform this?
I'm confusing the way to add extra actions to controller.
For example, after thread was created I need to set its state.
- We could do this by rewrite the action (copy full code then edit) but by this way, our addon might conflict with other addons that also extending the controller.
- Another way is execute parent::actionAddThread(); then add our actions.
PHP:
$return = parent::actionAddThread();
if ($return instanceof XenForo_ControllerResponse_Redirect && $return->responseCode == 200)
{
preg_match_all('([0-9]+)',$return->redirectTarget, $match);
$threadId = $match[0][count($match[0])-1];
if ($post_citation)
{
$writer = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
$writer->setExistingData($threadId);
$postWriter = $writer->getFirstMessageDw();
$postWriter->set('discussion_state', 'moderated');
$postWriter->save();
}
}
But you could see that we only are to get threadId by search thread id from redirectTarget since the parent controller return XenForo_ControllerResponse_Redirect.
Is this an good way to do? Do you have any better way to perform this?