【问题标题】:TYPO3 extbase forward , redirect actionTYPO3 extbase 转发,重定向操作
【发布时间】:2018-03-15 18:40:47
【问题描述】:

如何使用重定向或转发功能重定向到不同的操作?我的解决方案似乎不起作用

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

【问题讨论】:

  • 每次你想执行showAction时,你的代码似乎都会重定向到listAction。这是你想做的吗?
  • 我希望这两个操作都在同一个页面(.html 文件)上执行。 Typo3 有点强迫我为每个动作创建一个不同的 .html 文件,在我的例子中是 list.html 和 show.html 。而不是创建 show.html 我希望 showAction 在 list.html 中执行。
  • 我无法理解它背后的想法。 showAction 应该显示一些内容,主要是记录的详细信息,例如新闻扩展中的详细信息视图。我唯一一次使用重定向是当我例如更新记录并在保存更改后返回列表。恕我直言,您应该过度考虑自己的行为以及该做什么。
  • 你需要 showAction 做什么?
  • 我想这个想法是同时拥有单个项目的列表和详细视图?如果您只关心重用模板,您应该阅读部分内容。如果我正确理解了您问题背后的想法,那么它们是执行您正在寻找的事情的更优雅的方式。

标签: typo3 fluid extbase


【解决方案1】:

它不会那样工作。 如果您使用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
        )
    );  
}

这将填充您上面提到的模板

【讨论】:

  • 这样做但我收到以下错误:此请求不存在参数“searchProduct”。有关此错误的更多信息可能在线提供。最有可能的错误是指这一行:
猜你喜欢
  • 2017-03-25
  • 2016-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多