Hallo zusammen,
gibt es einen einfachen Weg die vorherige Action abzufragen?
Ich würde diese gerne an Fluid übergeben für einen "zurück"-Link.
Vorherige Action
Hi,
könntest vielleicht folgendes machen:
In deinem Controller legst du die Funktion protected function initializeView() {} an. Die wird im Prinzip bei jedem View als erstes aufgerufen und soll den aktuell aufgerufenen Controller-Namen z.B. in ein Cookie speichern.
Im Extbase Core Controller Tx_Extbase_MVC_Controller_ActionController gibt es das Attribut $actionMethodName, welches du in deinem eigenen Controller per $this->actionMethodName auslesen kannst (da alle Controlle standardmäßig vom ActionController erben).
<?php
/**
* Current ActionMethod Name
* @var string
*/
protected $currentActionMethodName;
/**
* The session data container
* @var array
*/
protected $sessionData = array();
/**
* Initializes the view before invoking an action method.
* Override this method to solve assign variables common for all actions or prepare the view in another way before the action is called.
* @return void
*/
protected function initializeView() {
$this->currentActionMethodName = $this->actionMethodName;
$this->storeSessionData();
}
/**
* Stores data to session
* @return void
*/
protected function storeSessionData() {
$this->sessionData['currentActionMethodName'] = $this->currentActionMethodName;
$GLOBALS['TSFE']->fe_user->setKey('ses', 'my_session_key', $this->sessionData);
$GLOBALS['TSFE']->fe_user->storeSessionData();
}
?>
Mit der folgenden Funktion kannst du dann auf die in der Session gespeicherten Daten wieder zu greifen und auswerten:
<?php
/**
* Loads data from session
* @return void
*/
protected function loadSessionData() {
$this->sessionData = $GLOBALS['TSFE']->fe_user->getKey('ses', 'my_session_key');
$this->currentActionMethodName = $this->sessionData['currentActionMethodName'];
}
?>
Viel Spaß beim Experimentieren 😉
Vielen Dank für den Ansatz Typo3Cuckoo!
Habe es so gelöst wie du geschrieben hast (mit ein paar Anpassungen).
Im Controller:
/**
* Action method name of the previous action
* @var string
*/
protected $previousActionMethodName;
/**
* Initialize the view
* @return void
*/
protected function initializeView() {
$this->previousActionMethodName = $GLOBALS['TSFE']->fe_user->getKey('ses', 'myExtLastAction');
if($this->actionMethodName !== 'showAction'){
$GLOBALS['TSFE']->fe_user->setKey('ses', 'myExtLastAction', $this->actionMethodName);
$GLOBALS["TSFE"]->fe_user->storeSessionData();
}
}
public function showAction(Tx_MyExt_Domain_Model_MyModel $MyModel) {
$this->view->assign('lastAction', substr($this->previousActionMethodName, 0, -6));
$this->view->assign('MyModel', $MyModel);
}
Und im Fluid Template dann
<f:link.action action="{lastAction}"><f:translate key="tx_myext_domain_model_mymodel.back_to_list" /></f:link.action>
Gern geschehen! 🙂