typo3 自定义小部件 viewhelper
typo3 custom widget viewhelper
我为一个扩展创建了一个自定义小部件 viewhelper
,它在空的 typo3 8.7 安装中运行良好。但是当我用相同的代码在需要的项目上使用它时,它会导致错误:
#1289422564: initiateSubRequest() can not be called if there is no valid controller extending TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController Got "NULL" in class ...
以前有人遇到过这样的错误吗?或者有人知道是什么原因导致了这种类型的错误吗?
<!-- This is the View List.html-->
{namespace Exhibitors = MyVendorName\MyExhibitors\ViewHelpers}
<ul class="second_lvl">
<Exhibitors:widget.AtoZNav objects="{feUserData}" as="filteredExhibitors" property="company">
<Exhibitors:widget.sort objects="{filteredExhibitors}" as="sortedExhibitors" property="company">
<f:for each="{filteredExhibitors}" as="feUser">
<li class="navLink">
{feUser.company}<br />
{feUser.company}
{feUser.www}<br />
</li>
</f:for>
</Exhibitors:widget.sort>
</Exhibitors:widget.AtoZNav>
</ul>
<f:link.action action="show">show detail page</f:link.action>
<?php
/**
* This is the SortViewHelper
*/
namespace MyVendorName\MyExhibitors\ViewHelpers\Widget;
class SortViewHelper extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetViewHelper
{
/**
* @param \TYPO3\CMS\Extbase\Persistence\QueryResultInterface $objects
* @param string $as
* @param string $property
* @return string
*/
public function render(\TYPO3\CMS\Extbase\Persistence\QueryResultInterface $objects, $as, $property)
{
return $this->initiateSubRequest();
}
}
<?php
/**
* This is the Sort Controller
*/
namespace MyVendorName\MyExhibitors\ViewHelpers\Widget\Controller;
class SortController extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController
{
/**
* @var \TYPO3\CMS\Extbase\Persistence\QueryResultInterface
*/
protected $objects;
public function initializeAction()
{
$this->objects = $this->widgetConfiguration['objects'];
}
/**
* @param mixed string $order
*/
public function indexAction($order = \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING)
{
$order = ($order == \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING) ? \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING : \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING;
$query = $this->objects->getQuery();
$query->setOrderings(array($this->widgetConfiguration['property'] => $order));
$modifiedObjects = $query->execute();
$this->view->assign('contentArguments', array($this->widgetConfiguration['as'] => $modifiedObjects));
$this->view->assign('order', $order);
}
}
<?php
/**
* This is AtoZNav ViewHelper
*/
namespace MyVendorName\MyExhibitors\ViewHelpers\Widget;
class AtoZNavViewHelper extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetViewHelper
{
/**
* @param \TYPO3\CMS\Extbase\Persistence\QueryResultInterface $objects
* @param string $as
* @param string $property
* @return string
*/
public function render(\TYPO3\CMS\Extbase\Persistence\QueryResultInterface $objects, $as, $property)
{
return $this->initiateSubRequest();
}
}
<?php
/**
* This is the Controller
*/
namespace MyVendorName\MyExhibitors\ViewHelpers\Widget\Controller;
class AtoZNavController extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController
{
/**
* @var \TYPO3\CMS\Extbase\Persistence\QueryResultInterface
*/
protected $objects;
public function initializeAction()
{
$this->objects = $this->widgetConfiguration['objects'];
}
/**
* @param string $char
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function indexAction($char = '%')
{
$query = $this->objects->getQuery();
$query->matching($query->like($this->widgetConfiguration['property'], $char . '%'));
$modifiedObjects = $query->execute();
$this->view->assign('contentArguments', array($this->widgetConfiguration['as'] => $modifiedObjects));
$this->view->assign('letters', range('A', 'Z'));
$this->view->assign('char', $char);
}
}
我遇到了同样的错误。您需要注入您的控制器,就像在流体分页小部件中完成的那样。书中缺少这部分内容。
<?php
/**
* This is the SortViewHelper
*/
namespace MyVendorName\MyExhibitors\ViewHelpers\Widget;
class SortViewHelper extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetViewHelper
{
protected $controller;
/**
* @param Controller/SortController $controller
*/
public function injectSortController(Controller\SortController $controller)
{
$this->controller = $controller;
}
/**
* @param \TYPO3\CMS\Extbase\Persistence\QueryResultInterface $objects
* @param string $as
* @param string $property
* @return string
*/
public function render(\TYPO3\CMS\Extbase\Persistence\QueryResultInterface $objects, $as, $property)
{
return $this->initiateSubRequest();
}
}
我为一个扩展创建了一个自定义小部件 viewhelper
,它在空的 typo3 8.7 安装中运行良好。但是当我用相同的代码在需要的项目上使用它时,它会导致错误:
#1289422564: initiateSubRequest() can not be called if there is no valid controller extending TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController Got "NULL" in class ...
以前有人遇到过这样的错误吗?或者有人知道是什么原因导致了这种类型的错误吗?
<!-- This is the View List.html-->
{namespace Exhibitors = MyVendorName\MyExhibitors\ViewHelpers}
<ul class="second_lvl">
<Exhibitors:widget.AtoZNav objects="{feUserData}" as="filteredExhibitors" property="company">
<Exhibitors:widget.sort objects="{filteredExhibitors}" as="sortedExhibitors" property="company">
<f:for each="{filteredExhibitors}" as="feUser">
<li class="navLink">
{feUser.company}<br />
{feUser.company}
{feUser.www}<br />
</li>
</f:for>
</Exhibitors:widget.sort>
</Exhibitors:widget.AtoZNav>
</ul>
<f:link.action action="show">show detail page</f:link.action>
<?php
/**
* This is the SortViewHelper
*/
namespace MyVendorName\MyExhibitors\ViewHelpers\Widget;
class SortViewHelper extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetViewHelper
{
/**
* @param \TYPO3\CMS\Extbase\Persistence\QueryResultInterface $objects
* @param string $as
* @param string $property
* @return string
*/
public function render(\TYPO3\CMS\Extbase\Persistence\QueryResultInterface $objects, $as, $property)
{
return $this->initiateSubRequest();
}
}
<?php
/**
* This is the Sort Controller
*/
namespace MyVendorName\MyExhibitors\ViewHelpers\Widget\Controller;
class SortController extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController
{
/**
* @var \TYPO3\CMS\Extbase\Persistence\QueryResultInterface
*/
protected $objects;
public function initializeAction()
{
$this->objects = $this->widgetConfiguration['objects'];
}
/**
* @param mixed string $order
*/
public function indexAction($order = \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING)
{
$order = ($order == \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING) ? \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING : \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING;
$query = $this->objects->getQuery();
$query->setOrderings(array($this->widgetConfiguration['property'] => $order));
$modifiedObjects = $query->execute();
$this->view->assign('contentArguments', array($this->widgetConfiguration['as'] => $modifiedObjects));
$this->view->assign('order', $order);
}
}
<?php
/**
* This is AtoZNav ViewHelper
*/
namespace MyVendorName\MyExhibitors\ViewHelpers\Widget;
class AtoZNavViewHelper extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetViewHelper
{
/**
* @param \TYPO3\CMS\Extbase\Persistence\QueryResultInterface $objects
* @param string $as
* @param string $property
* @return string
*/
public function render(\TYPO3\CMS\Extbase\Persistence\QueryResultInterface $objects, $as, $property)
{
return $this->initiateSubRequest();
}
}
<?php
/**
* This is the Controller
*/
namespace MyVendorName\MyExhibitors\ViewHelpers\Widget\Controller;
class AtoZNavController extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController
{
/**
* @var \TYPO3\CMS\Extbase\Persistence\QueryResultInterface
*/
protected $objects;
public function initializeAction()
{
$this->objects = $this->widgetConfiguration['objects'];
}
/**
* @param string $char
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function indexAction($char = '%')
{
$query = $this->objects->getQuery();
$query->matching($query->like($this->widgetConfiguration['property'], $char . '%'));
$modifiedObjects = $query->execute();
$this->view->assign('contentArguments', array($this->widgetConfiguration['as'] => $modifiedObjects));
$this->view->assign('letters', range('A', 'Z'));
$this->view->assign('char', $char);
}
}
我遇到了同样的错误。您需要注入您的控制器,就像在流体分页小部件中完成的那样。书中缺少这部分内容。
<?php
/**
* This is the SortViewHelper
*/
namespace MyVendorName\MyExhibitors\ViewHelpers\Widget;
class SortViewHelper extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetViewHelper
{
protected $controller;
/**
* @param Controller/SortController $controller
*/
public function injectSortController(Controller\SortController $controller)
{
$this->controller = $controller;
}
/**
* @param \TYPO3\CMS\Extbase\Persistence\QueryResultInterface $objects
* @param string $as
* @param string $property
* @return string
*/
public function render(\TYPO3\CMS\Extbase\Persistence\QueryResultInterface $objects, $as, $property)
{
return $this->initiateSubRequest();
}
}