简体   繁体   中英

PaginateViewHelper redirect to request page

I'm using TYPO3\\Fluid\\ViewHelpers\\PaginateViewHelper in my index action which listing some items. Each item has actions which are done on the fly, so after action is called and processed it's back to the index action.

public function deleteAction(Item $item) {
    $this->itemService->remove($item);
    $this->redirect('index');
}

Unfortunately in this case I'm getting redirected to the first page of index. Is there possibility to redirect to the page where I'm triggering delete action? Can I also obtain arguments of subrequest send to PaginateController ?

I know I can use AJAX call instead or write my own pagination, but I'd like to use existing solution if it's possible.

To keep the GET Parameters you can use addQueryString="1" in the LinkViewHelper... maybe this is already enough to keep the current page when using redirect() in the controller.

Otherwise you can use the UriBuilder of the controller to generate a URI including the desired page in your pagination and other parameters and then use the function redirectToUri() to redirect the user to the desired URI.

https://typo3.org/api/typo3cms/class_t_y_p_o3_1_1_c_m_s_1_1_extbase_1_1_mvc_1_1_web_1_1_routing_1_1_uri_builder.html

You can do something like this

$referringRequest = $this->request->getReferringRequest();
if ($referringRequest !== null) {
    $this->redirectToRequest($referringRequest);
}

This only works, if the referring request is sent with the original request, which is the case for Fluid Forms, which you should use for unsafe requests (POST, PUT, DELETE).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM