如何使用重定向或转发功能重定向到不同的操作?我的解决方案似乎无法运作
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>
答案 0 :(得分:1)
redirect
或forward
,则会重置变量分配。
您可以在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
)
);
}
这将填写您上面提到的模板