2017-10-04 68 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」。 有關此錯誤的更多信息可能在線提供。最有可能的錯誤是指這一行: