I have a problem submitting a post request to controller. I Created a new table in database Product. I created after the model, Repository and Controller. Then I registered in the plugin the method list which gets a list of product. It works very well but in the List.html I have put a form where I want to submit something to the same controller where list is but this time is a POST method. I get action is not allowed by this plugin/module.
[ext_localconf.php]
/***************
* Custom PLugins
*/
ExtensionUtility::configurePlugin(
'youtube_demo',
'InventoryList',
[
StoreInventoryController::class => 'list',
],
[StoreInventoryController::class => '',],
);
[StoreInventoryController]
<?php
namespace Contencance\YoutubeDemo\Controller;
use Contencance\YoutubeDemo\Domain\Repository\ProductRepository;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
/**
* Class StoreInventoryController
*
* @package MyVendor\StoreInventory\Controller
*/
class StoreInventoryController extends ActionController
{
/**
* @var ProductRepository
*/
private $productRepository;
/**
* Inject the product repository
*
* @param \MyVendor\StoreInventory\Domain\Repository\ProductRepository $productRepository
*/
public function injectProductRepository(ProductRepository $productRepository)
{
$this->productRepository = $productRepository;
}
/**
* list Action
*
* @return void
*/
public function listAction()
{
$products = $this->productRepository->findAll();
$this->view->assign('products', $products);
}
/**
* store Action
*
* @return void
*/
public function storeAction()
{
var_dump("Hellow World");
die();
}
}
I tried adding the "Store" method in ext_location.php but it got called imediatly I want it only when submitting.
[List.html]
<table border="1" cellspacing="1" cellpadding="5">
<tr>
<td>Product name</td>
<td>Product description</td>
<td>Quantity</td>
</tr>
<f:for each="{products}" as="product">
<tr>
<td align="top">{product.name}</td>
<td align="top"><f:format.crop maxCharacters="100">{product.description}</f:format.crop></td>
<td align="top">{product.quantity}</td>
</tr>
</f:for>
</table>
<f:form action="store" controller="StoreInventory" objectName="gamingData" method="post">
<label>Enter</label><br>
<f:form.textfield property="game-desc" /><br>
<f:form.button>Submit</f:form.button>
</f:form>
CodePudding user response:
You need to add store
to the list of methods in your ext_localconf.php, that's correct.
But you need to add it after list
=> list, store
.
The first entry in the list is executed by default (if no action given).
Full code:
ExtensionUtility::configurePlugin(
'youtube_demo',
'InventoryList',
[
StoreInventoryController::class => 'list, store',
],
[StoreInventoryController::class => '',],
);