2017-10-04 56 views
0

我如何重定向到使用重定向或转发功能的不同动作?我的解决方案似乎不工作TYPO3 extbase转发,重定向动作

public function listAction() { 
    $products = $this->productRepository->findAll(); 
    $this->view->assign('products', $products); 
} 

public function showAction() { 
    $var = $this->request->getArgument('searchProduct'); 
    $foundProd = new \MyVendor\Inventory\Domain\Model\Product($var);  
    $prod = $this->productRepository->getProduct($foundProd); 
    \TYPO3\CMS\Core\Utility\DebugUtility::debug($prod); 

    $this->view->assign('test',$prod); 
    $this->redirect('list',NULL,NULL,array('')); 
    // $this->forward('list',NULL, NULL, $this->request->getArguments()); 
} 

在视图中,我试图展现foundProduct在同一个页面(而不是建立一个新文件show.html)

<f:widget.paginate objects="{products}" as="paginatedProducts" 
     configuration="{itemsPerPage: 10, insertAbove: 0, insertBelow: 1, maximumNumberOfLinks: 10}"> 
      <f:for each="{paginatedProducts}" as="productx"> 

        <tr>  
          <td align="top">{productx.uid}</td> 
          <td align="top">{productx.name}</td> 
          <td align="top"><f:format.crop maxCharacters="100">{productx.description}</f:format.crop></td> 
          <td align="top">{productx.quantity}</td> 
        </tr> 
      </f:for> 
       </f:widget.paginate> 
    </table> 

</div> 
<div class="col-sm-5"> 

<f:form method="post" controller="Inventory" action="show" name="searchProduct" object="{searchProduct}"> 
<label> Product Name <span class="required"></span><br /> 
    <f:form.textfield property="name" /></label><br /> 
<f:form.submit class="submit" value="Submit"/> 

<div> 
<f:for each ="{test}" as ="p"> 
    <P>Numele produsului : {p.name}</P> 
    <p>Descriere : {p.description}</p> 
    <p>Cantitate : {p.quantity} </p> 
</f:for> 
</div> 
</div> 

编辑:list.html file. Basically when i click Submit i want to show on the same page the product found from the database.

This is how it works atm

+0

提到的模板。那是你想要做的吗? –

+0

我希望这两个动作都在同一页面(.html文件)上执行。 Typo3有点迫使我为每个动作创建一个不同的.html文件,在我的例子中是list.html和show.html。我不希望创建show.html,而是希望showAction在list.html中执行。 –

+0

我无法理解它背后的想法。 'showAction'应该显示一些内容,主要是新闻扩展中的细节视图等记录的细节。我使用重定向的唯一时间是当我例如更新记录并在保存更改后返回列表。你应该过度考虑你的行为以及在那里做些什么。 –

回答

0

它不会那样工作。 如果使用redirectforward,则重置变量分配。

您可以listAction内指定多个属性:

public function listAction() { 
    $products = $this->productRepository->findAll(); 

// from your showAction 
    $var = $this->request->getArgument('searchProduct'); 
    $foundProd = new \MyVendor\Inventory\Domain\Model\Product($var);  
    $prod = $this->productRepository->getProduct($foundProd); 


    $this->view->assignMultiple(
     array(
      'products' => $products, 
      'test' => $prod 
     ) 
    ); 
} 

这将填补你的代码似乎要执行`showAction`每次重定向到`listAction`你上面

+0

这样做,但我得到以下错误:此请求不存在参数“searchProduct”。 有关此错误的更多信息可能在线提供。最有可能的错误是指这一行: