---
title: "Vorherige Action"
url: "https://www.typo3.net/d/108241-vorherige-action"
source: "typo3.net"
tags: ["Extensions","Extbase","Fluid","Frage"]
created: "2011-11-16"
last_reply: "2011-11-18"
replies: 3
solved: false
page: 1
pages: 1
lang: "de"
---

# Vorherige Action

Extensions › Extbase · 3 Antworten · gestartet 2011-11-16

## Eröffnungsbeitrag

**jank** · 2011-11-16 · [Beitrag #1](https://www.typo3.net/d/108241-vorherige-action/1)

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.

## Antworten

### [#2](https://www.typo3.net/d/108241-vorherige-action/2) · Typo3Cuckoo · 2011-11-17

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
<?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
<?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 ;)

### [#3](https://www.typo3.net/d/108241-vorherige-action/3) · jank · 2011-11-18

Vielen Dank für den Ansatz Typo3Cuckoo!

Habe es so gelöst wie du geschrieben hast (mit ein paar Anpassungen).

Im Controller:

```php
/**
 * 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

```html
<f:link.action action="{lastAction}"><f:translate key="tx_myext_domain_model_mymodel.back_to_list" /></f:link.action>
```

### [#4](https://www.typo3.net/d/108241-vorherige-action/4) · Typo3Cuckoo · 2011-11-18

Gern geschehen! :)

---

Quelle: „Vorherige Action“, typo3.net, https://www.typo3.net/d/108241-vorherige-action
Beiträge von Mitgliedern des Forums. Bitte mit Link auf die Diskussion zitieren.
