我只是尝试从javascript中将一个值传递给我的控制器中的一个action,然后将该值返回:
这是我的控制器:
<?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。
这是我尝试过的:
<f:link.action controller="Custom" action="test" arguments="{myVar: sessionStorage.getItem('test')}" class="mbButton">Download</f:link.action>我明白了: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: 1}" class="mbButton">Download</f:link.action>然后我得到1作为响应。
发布于 2016-10-24 21:16:13
在控制器中:
public function testAction()
{
$this->view->assign('test', $someVariable);..。
在流体中:
<f:link.action controller="Custom" action="test" arguments="{myVar: test}" class="mbButton" noCacheHash="1">Download</f:link.action>我真的不明白sessionStorage是什么,你想用它做什么。如果您将testAction中的$someVariable替换为sessionStorage,它应该可以工作。
发布于 2016-10-25 23:37:20
这是框架的一部分,出于安全原因,它是无法避免的。从您的模板中提供正确的ID;如果需要的话,创建一个ViewHelper来处理它的存储(但是要注意,如果您混合了缓存和未缓存的插件!)
此外,您的链接的arguments参数中存在语法错误:
arguments="{myVar: sessionStorage.getItem('test')}"不会起作用。如果您的项目是一个变量,并且其上的“sessionStorage”实现了测试或具有属性“ArrayAccess”的getter,请使用:
arguments="{myVar: sessionStorage.item.test}"https://stackoverflow.com/questions/40216558
复制相似问题