I have a new field I added to threads that will be displayed in forum view with the threads.
I've read up on different ways, such as using $session or $GLOBALS to send the new field to the datawriter.
But I tried another method, that I couldn't find here that I used, and want to know if there are any drawbacks to it.
We know on actionAddThread that a check is made to ensure the new thread to be saved came via post only. So what I did is this in my controller:
and in the DW, as I know $_POST is there (but I check for it anyway, you never know...):
I've tested the above, and it works as expected (my controllers changes are reflected in the $_POST[''my_new_field']). As I never came across the option here to simply change the $_POST field in the controller public proxy, is there any negatives to it that I'm missing. It works, and doesn't seem as hacky,
I've read up on different ways, such as using $session or $GLOBALS to send the new field to the datawriter.
But I tried another method, that I couldn't find here that I used, and want to know if there are any drawbacks to it.
We know on actionAddThread that a check is made to ensure the new thread to be saved came via post only. So what I did is this in my controller:
Code:
$forumId = $this->_input->filterSingle('node_id', XenForo_Input::UINT);
$forumName = $this->_input->filterSingle('node_name', XenForo_Input::STRING);
$ftpHelper = $this->getHelper('ForumThreadPost');
$forum = $ftpHelper->assertForumValidAndViewable($forumId ? $forumId : $forumName);
$myNewField = $this->_input->filterSingle('my_new_field', XenForo_Input::STRING);
/*
... code for permission check...
... code to look for a specific syntax, and if found change $myNewField to reflect it, and then were done
so send it back to $_POST['my_new_field']
*/
$_POST['my_new_field'] = $myNewField;
return parent::actionAddThread();
and in the DW, as I know $_POST is there (but I check for it anyway, you never know...):
Code:
protected function _discussionPreSave()
{
$myNewField = isset($_POST[''my_new_field']) ? $_POST['my_new_field'] : '';
/*
... some validation checks to throw the message to my new field if required.
*/
$this->set(''my_new_field', $myNewField);
return parent::_discussionPreSave();
}
I've tested the above, and it works as expected (my controllers changes are reflected in the $_POST[''my_new_field']). As I never came across the option here to simply change the $_POST field in the controller public proxy, is there any negatives to it that I'm missing. It works, and doesn't seem as hacky,
Last edited: