Jaxel
Well-known member
I'm not exactly sure how I would do that...Okay, that's what I thought you were doing. How about not doing that separate AJAX call at all, and having the necessary templates etc. to refresh your comment list (or just the latest comments) be returned from the same request that submits the form data? Having that extra XenForo.ajax() call is rather wasteful of resources. I've got to take the kids to nursery now, but I'll embellish some details when I return unless you've already worked it out.![]()
Why is it a waste of resources? The queries will be going either way, wont they?
Below is the code for my comment switcher, and the comment poster
Code:
public function actionMediaComments()
{
$mediaParts = explode('.', $this->slugs[0]);
$mediaID = end($mediaParts);
if (!$media = $this->getModelFromCache('EWRmedio_Model_Media')->getMediaByID($mediaID))
{
return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, 'media');
}
$options = XenForo_Application::get('options');
$start = $this->_input->filterSingle('page', XenForo_Input::UINT) < 1 ? 1 : $this->_input->filterSingle('page', XenForo_Input::UINT);
$stop = $options->EWRmedio_commentcount;
$viewParams = array(
'perms' => $this->perms,
'start' => $start,
'stop' => $stop,
'media' => $media,
'count' => $this->getModelFromCache('EWRmedio_Model_Comments')->getCommentCount($media),
'comments' => $this->getModelFromCache('EWRmedio_Model_Comments')->getComments($media, $start, $stop),
);
return $this->responseView('EWRmedio_ViewPublic_MediaComments', 'EWRmedio_MediaComments', $viewParams);
}
public function actionMediaPost()
{
$mediaParts = explode('.', $this->slugs[0]);
$mediaID = end($mediaParts);
if (!$media = $this->getModelFromCache('EWRmedio_Model_Media')->getMediaByID($mediaID))
{
return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, 'media');
}
if ($this->_request->isPost())
{
$input['username'] = $this->_input->filterSingle('username', XenForo_Input::STRING);
$input['message'] = $this->getHelper('Editor')->getMessageText('message', $this->_input);
$this->getModelFromCache('EWRmedio_Model_Comments')->postComment($input, $media);
}
return $this->responseRedirect(
XenForo_ControllerResponse_Redirect::SUCCESS,
XenForo_Link::buildPublicLink('full:media', $media),
null,
array(
'newurl' => XenForo_Link::buildPublicLink('full:media/comments', $media),
'status' => new XenForo_Phrase('your_comment_has_been_posted')
)
);
}