admin wrote:
Did you got sorted out ? since then ?
Almost, but not completely.
I have made my button look like this:
<a href="/index.php?option=com_cphdans&task=team.registerturnup&team=<?php echo $this->item->id; ?>&id=<?php echo $rel->id; ?>
This will trigger my team controller where I have a function called registerTurnup. This works.
But, my main issue now, is I'm redirected to a page without content instead of staying on the same page as the button.
I have tried a redirect back, but can't get HTTP_REFERER value in my controller function, so not sure how to solve that....
This is my function as of now:
$data = new stdClass();
$data->student = JRequest::getInt('id',0);
$data->team = JRequest::getInt('team',0);
$data->date = date("Y-m-d H:i:s", strtotime("now"));
$db = JFactory::getDbo();
$sql = 'SELECT id FROM #__cphdans_turnups WHERE team = '.$data->team.' && student = '.$data->student.' && DATE(`date`) = CURDATE()';
$db->setQuery($sql);
// Brug loadResult() hvis der kun forventes en værdi
$result = $db->loadResult();
if (!$result) { // insert timestamp
$result = JFactory::getDbo()->insertObject('#__cphdans_turnups', $data);
}
// TODO - GET THIS RIGHT...............................................................................................................
// redirect user back to referring url
$url = $_SERVER['HTTP_REFERER'];
$this->setRedirect('/timeregistrering/team/team/391-hold-1'); // should be $url, but it is empty...
// TODO - GET THIS RIGHT...............................................................................................................