对于我的TYPO3 Extbase扩展,我想做一些分页。到目前为止,ajax调用和其他一切都很好。但是当我在ajax调用期间尝试访问$this->settings
数组时,存储了flexform前端插件值,我总是得到null
。该部分看起来像这样:
$limit = $this->settings['result']['amount'];
$orderType = $this->settings['order']['type'];
$orderFields = $this->settings['additionorder']['fields'];
$formArr = array();
$this->request->hasArgument('offset') ? $offset = $this->request->getArgument('offset') : null;
$forms = $this->formRepository->findFormsChunked(
$orderFields, $orderType, $limit, $offset
);
foreach ($forms as $key => $form) {
$formArr[] = array(
'formUid' => $form->getUid(),
'formName' => $form->getName(),
'formFile' => $form->getFile()->getOriginalResource()->getPublicUrl(),
'formType' => $form->getFormtype()->getUid()
);
}
return json_encode($formArr);
在我的ajax调用期间,$ this->设置为空,但我无法想象为什么。值是否仅在渲染过程中可用,这在ajax调用期间不会发生?
感谢您的帮助。
更新
据我所知,flexform值只传递给选定的控制器动作(即displaycond),如下所示:
<displayCond>FIELD:switchableControllerActions:=:Controller->ajax:AND:FIELD:switchableControllerActions:=:Controller->normal</displayCond>
并在选择菜单中:
<numIndex index="1">
<numIndex index="0">LLL:EXT:ext_formpool/Resources/Private/Language/locallang.xlf:name</numIndex>
<numIndex index="1">Controller->normal;Controller->ajax</numIndex>
</numIndex>
那么值也应该传递给ajaxAction吗?目前它们不可用......
解决方案
不幸的是,如果你使用单独的页面类型进行ajax调用,它根本不起作用。 flexform存储在数据库中,仅在框架加载过程中进行解析。您可以通过包含配置管理器来检查这一点,并尝试解析内容对象&#34; pi_flexform&#34;领域。或者您注入了flexformservice,它在ajax调用期间也未加载。您必须使用eID机制来实现此目的。
答案 0 :(得分:1)
为什么不,而不是将您的插件呈现为内容对象,直接在您的ajax调用中解决它?
plugin_yourext_ajax = PAGE
plugin_yourext_ajax {
typeNum = 2000
config {
disableAllHeaderCode = 1
xhtml_cleaning = 1
admPanel = 0
additionalHeaders = Content-type: text/plain
no_cache = 1
}
10 = USER
10 {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
pluginName = YourPLugin
extensionName = YourExt
controller = ControllerName
vendorName = Vendor
action = ajax
switchableControllerActions {
YourPlugin {
1 = ajax
}
}
persistence =< plugin.tx_your_ext.persistence
view =< plugin.tx_your_ext.view
update =< plugin.tx_your_ext.update
settings < plugin.tx_your_ext.settings
}
}
这将在每次通话时引导您的分机,而不是寻呼
答案 1 :(得分:1)
我也有这个问题,比我发现你需要使用renderObj,它将使用ContentObjectRenderer类。我需要从我的列表模板f:链接到详细信息页面的Flexform值。
所以在我的情况下,我也想要Ajax分页。我只是在我自己的新闻扩展的列表视图中使用了默认的Fluid paginate小部件。如果客户端没有javascript它仍然可以工作。因此,创建很酷的Ajax分页真的很容易!
typeNum的Typoscript:
$('body').on('click', 'div.jpnews-list ul.f3-widget-paginator li a', (function (e) {
e.preventDefault();
paginateToPageURI = $(this).attr('href') + '&type=' + TYPO3pageType;
var parentDivOfNewsList = $(txJpNews).parent();
$(txJpNews).css('opacity', 0.4);
$(parentDivOfNewsList).append(spinnerHTML);
$.ajax({
type: 'POST',
url: paginateToPageURI,
data: $(this).serializeArray(),
success: function (data) {
$(parentDivOfNewsList).html(data);
},
error: function (xhr, thrownError) {
var msg = "<b>Sorry but there was an error, please contact us..</b><br>";
$(parentDivOfNewsList).html(msg + xhr.status + ' ' + thrownError);
}
});
})
可能的javascript的一部分:
require 'torch'
require 'nn'
require 'cudnn'
require 'cunn'
require 'cutorch'
require 'nngraph'
data1 = torch.ones(4,20):cuda()
data2 = torch.ones(4,10):cuda()
tmodel = nn.Sequential()
tmodel:add(nn.Linear(20,10))
tmodel:add(nn.Linear(10,10))
parallelModel = nn.ParallelTable()
parallelModel:add(tmodel)
parallelModel:add(nn.Identity())
parallelModel:add(nn.Identity())
model = parallelModel
if true then
local function sharingKey(m)
local key = torch.type(m)
if m.__shareGradInputKey then
key = key .. ':' .. m.__shareGradInputKey
end
return key
end
-- Share gradInput for memory efficient backprop
local cache = {}
model:apply(function(m)
local moduleType = torch.type(m)
if torch.isTensor(m.gradInput) and moduleType ~= 'nn.ConcatTable' then
local key = sharingKey(m)
if cache[key] == nil then
cache[key] = torch.CudaStorage(1)
end
m.gradInput = torch.CudaTensor(cache[key], 1, 0)
end
end)
end
if true then
cudnn.fastest = true
cudnn.benchmark = true
-- Wrap the model with DataParallelTable, if using more than one GPU
local gpus = torch.range(1, 2):totable()
local fastest, benchmark = cudnn.fastest, cudnn.benchmark
local dpt = nn.DataParallelTable(1, true, true)
:add(model, gpus)
:threads(function()
local cudnn = require 'cudnn'
cudnn.fastest, cudnn.benchmark = fastest, benchmark
end)
dpt.gradInput = nil
model = dpt:cuda()
end
newmodel = nn.Sequential()
newmodel:add(model)
input1 = nn.Identity()()
input2 = nn.Identity()()
input3 = nn.Identity()()
out = newmodel({input1,input2,input3})
r1 = nn.NarrowTable(1,2)(out)
r2 = nn.NarrowTable(2,2)(out)
f1 = nn.JoinTable(2)(r1)
f2 = nn.JoinTable(2)(r2)
n1 = nn.Sequential()
n1:add(nn.Linear(20,5))
n2 = nn.Sequential()
n2:add(nn.Linear(20,5))
f11 = n1(f1)
f12 = n2(f2)
foutput = nn.JoinTable(2)({f11,f12})
g = nn.gModule({input1,input2,input3},{foutput})
g = g:cuda()
g:forward({data1, data2, data2})
g:backward({data1, data2, data2}, torch.rand(4,10):cuda())
答案 2 :(得分:1)
我们通过将插件的uid
(内容元素)添加到Ajax请求的URL,然后使用FlexFormService
加载flexform配置来解决了这个问题。
在Controller中构建URL:
$url = $this->uriBuilder->setTargetPageType(1234)->uriFor(
'ajaxAction',
[
'contentUid' => (int) $this->configurationManager->getContentObject()->data['uid']
]
);
通过设置弹性格式设置来初始化Controller操作:
class SomeController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
protected $flexFormService;
protected $flexformSettings = [];
public function injectFlexFormService(\TYPO3\CMS\Extbase\Service\FlexFormService $flexFormService): void
{
$this->flexFormService = $flexFormService;
}
public function initializeAction(): void
{
parent::initializeAction();
if ($this->request->hasArgument('contentUid')) {
$recordUid = (int) $this->request->getArgument('contentUid');
$record = TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('tt_content', $recordUid, 'pi_flexform');
if (!empty($record['pi_flexform'])) {
$this->flexformSettings = $this->flexFormService->convertFlexFormContentToArray($record['pi_flexform']);
}
}
}
public function ajaxAction(): void
{
//access $this->flexformSettings;
}
}
答案 3 :(得分:0)
您是否在ext_tables.php
声明了您的柔印?我通常这样做:
$extensionName = t3lib_div::underscoredToUpperCamelCase($_EXTKEY);
$pluginNames = array('pluginname1','pluginname2','...');
foreach ($pluginNames as $pluginName) {
$pluginSignature = strtolower($extensionName) . '_'.$pluginName;
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist'][$pluginSignature] = 'recursive';
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] = 'pi_flexform';
t3lib_extMgm::addPiFlexFormValue($pluginSignature, 'FILE:EXT:' . $_EXTKEY . '/Configuration/FlexForms/'.$pluginName.'.xml');
}