Pass data in redirect() - Typo3

血红的双手。 提交于 2019-12-11 12:34:28

问题


I have a form after validation if any error occur the page will redirected to the edit itself with an error message.How to pass previous data and an error message through redirect() in typo3 ?

$this->redirect($action_name,$controllername, $extensionName, array('data',$data));

Is it right?

my action name is 'edit' But it is redirect to 'list' .Please help me to solve this issue.


回答1:


The arguments to pass to the redirect-target have to be given as associative array. The key is the argument name (as in the actions method header, without the $), the value is the argument value. Looks like this:

$this->redirect(
    $action_name,
    $controllername,
    $extensionName,
    [
        'data' => $data
    ]
);

How exactly $data is encoded in the URL depends on its type. Persistent objects are encoded as their ID, scalars are encoded as simple strings. How they arrive in the other action depends on that actions typehints and @param annotations.

To redirect to the same controller or extension, you can pass $controllerNameand $extensionName as null.




回答2:


The arguments are passed as an array with key value pairs, where the key is the parameter name. This assumes that your target action has a parameter named "data". $this->redirect($action_name,$controllername, $extensionName, array('data' =>$data));




回答3:


Jost's answer is sufficient to your question but if you want to know more:

  1. your controller action should be editAction()
  2. you should register your action/controller in ext_localconf.php
  3. you have to allow your action in plugin Flexform configuration [if more actions or switchableControllerActions]
  4. clear install tool cache sometimes create magik ;)

Reference: extBase Fluid Book



来源:https://stackoverflow.com/questions/38299136/pass-data-in-redirect-typo3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!