简体   繁体   English

PaginateViewHelper重定向到请求页面

[英]PaginateViewHelper redirect to request page

I'm using TYPO3\\Fluid\\ViewHelpers\\PaginateViewHelper in my index action which listing some items. 我在索引操作中使用了TYPO3\\Fluid\\ViewHelpers\\PaginateViewHelper ,其中列出了一些项目。 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 ? 我也可以获取发送给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. 我知道我可以改用AJAX调用或编写自己的分页,但是如果可能的话,我想使用现有的解决方案。

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. 要保留GET参数,您可以在LinkViewHelper中使用addQueryString =“ 1” ...也许这足以在控制器中使用redirect()时保留当前页面。

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. 否则,您可以使用控制器的UriBuilder生成URI,其中包括分页中所需的页面和其他参数,然后使用功能redirectToUri()将用户重定向到所需的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 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). 仅当引用请求与原始请求一起发送时才有效(流体形式就是这种情况),您应该将其用于不安全的请求(POST,PUT,DELETE)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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