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

Posting Thread Using Datawriter

Cooper

Active member
#1
Hi

Having a few issues using Datawriter - getting 500 error when trying to do the below, creating a new thread:

First PHP Page (included in 2nd)
PHP:
$startTime = microtime(true);
$fileDir = '/var/www/vhosts/domain.com/httpdocs/forum';
 
require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
 
XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);
 
XenForo_Session::startPublicSession();
 
$visitor = XenForo_Visitor::getInstance();
 
$userid = $visitor->getUserId();
$username = $visitor->get('username');
I know this code block works fine as I use it in other scripts. (domain name removed as is for a new project)

On another page (with the above included) I have:

PHP:
$writer = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
  $writer->set('user_id', $userid);
        $writer->set('username', $username);
        $writer->set('title', $title);
        $postWriter = $writer->getFirstMessageDw();
        $postWriter->set('message', $intro);
 
        $writer->set('node_id', $nodeid);
                $writer->preSave();
                $writer->save();
                $thread = $writer->getMergedData();
                  return $this->responseRedirect(
                XenForo_ControllerResponse_Redirect::SUCCESS,
                $this->getDynamicRedirect(),
                new XenForo_Phrase('your_message_has_been_sent')
            );
I just get a 500 error, any thoughts on where I'm going wrong?

TIA :)
 

Cooper

Active member
#3
PHP error reporting is on, nothing striking in error_logs. Dreamweaver syntax highlighter is pointing to most of the second block having an error. Perhaps I need to include another file?
 

Cooper

Active member
#4
Worked perfectly when I dropped the below :)

PHP:
 return $this->responseRedirect(
                XenForo_ControllerResponse_Redirect::SUCCESS,
                $this->getDynamicRedirect(),
                new XenForo_Phrase('your_message_has_been_sent')
            );