Pass data in redirect() - Typo3

2019-07-25 08:10发布

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.

3条回答
女痞
2楼-- · 2019-07-25 08:38

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.

查看更多
时光不老,我们不散
3楼-- · 2019-07-25 08:49

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

查看更多
我只想做你的唯一
4楼-- · 2019-07-25 08:55

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

查看更多
登录 后发表回答