Posting Thread Using Datawriter

Cooper

Active member
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 :)
 
If you're developing on a local environment you should turn PHP error display on so you can see the actual error instead of just a 500 page.
 
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?
 
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')
            );
 
Top Bottom