私は単に私のコントローラからのアクションにJavaScriptから値を渡すとバック値を返すようにしてみてください。は、コントローラにはJavaScript変数の値を送るアクション
<?php
namespace Black\Test\Controller;
/**
* CustomController
*/
class CustomController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
/**
* action test
*
* @return void
*/
public function testAction()
{
$myVar = $this->request->getArgument('myVar');
echo "myVar = ". $myVar;
}
}
どのように私は:これは私のコントローラは
ですそれを動作させるために私のボタンをセットアップしなければなりませんか? 私はsessionStorageアイテムtest
を渡そうとします。
これは私が試したものです:私は手動で例えば値を設定する場合The argument "arguments" was registered with type "array", but is of type "string" in view helper "TYPO3\CMS\Fluid\ViewHelpers\Link\ActionViewHelper
:
<f:link.action controller="Custom" action="test" arguments="{myVar: sessionStorage.getItem('test')}" class="mbButton">Download</f:link.action>
は私が手
<f:link.action controller="Custom" action="test" arguments="{myVar: 1}" class="mbButton">Download</f:link.action>
は、それから私は、応答として
1
を取得します。流体中
public function testAction()
{
$this->view->assign('test', $someVariable);
...
:コントローラで
問題があり、その代わりに、私はJavaScriptを渡す必要がtest' 'の可変値。例えば'arguments =" {myVar:sessionStorage.getItem( 'myItem')}} '' ' これはsessionStorageです:https://developer.mozilla.org/de/docs/Web/API/Window/sessionStorage – Black
次に、プレースホルダを引数として使用して、javascript 'arguments =" {myVar: ' __PLACEHOLDER __ '} "' 「onclick =」this.href = this.href.replace(/ __PLACEHOLDER __/g、sessionStorage.getItem( 'myItem')) "' –
私はすでにそれを試しましたが、404ページにリダイレクトされます。流体ボタンにハードコードされている場合にのみ機能するようです:( – Black