Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typo3 类型3&;tx_news需要ViewHelper来显示类别中的实体计数_Typo3_Typo3 7.6.x_Tx News - Fatal编程技术网

Typo3 类型3&;tx_news需要ViewHelper来显示类别中的实体计数

Typo3 类型3&;tx_news需要ViewHelper来显示类别中的实体计数,typo3,typo3-7.6.x,tx-news,Typo3,Typo3 7.6.x,Tx News,任务:在类别菜单中显示每个类别中的项目计数,如 第一类(38) 第二类(14) 等等 我试过按美元需求计数,但没有成功 <?php namespace HIT\huskytheme\ViewHelpers\News; class CountCategoriesViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper { /** * @var \Geo

任务:在类别菜单中显示每个类别中的项目计数,如

  • 第一类(38)
  • 第二类(14)
  • 等等
我试过按美元需求计数,但没有成功

<?php
    namespace HIT\huskytheme\ViewHelpers\News;

    class CountCategoriesViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {

        /**
         * @var \GeorgRinger\News\Domain\Repository\NewsRepository
         * @inject
         */
        protected $newsRepository = null;

        /**
         * 
         * @param string $category
         * @return string
         */
        public function render($category) {

            $demand = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('GeorgRinger\\News\\Domain\\Model\\Dto\\NewsDemand');
            //$demand->setDateField('datetime');

            $demand->setStoragePage(10, true);

            // for example by id = 2
            $demand->setCategories(2);

            $demand->setCategoryConjunction('and');
            $demand->setIncludeSubCategories('1');
            //$demand->setArchiveRestriction($settings['archiveRestriction']);

            $statistics = $this->newsRepository->countByCategories($demand);
            \TYPO3\CMS\Core\Utility\DebugUtility::debug($statistics);

            return $this->newsRepository->countByCategories($demand); 

        }

    }

没有方法
countByCategories
实现类似于需求对象的东西。请直接呼叫数据库

没有方法
countByCategories
实现类似于需求对象的功能。请直接呼叫数据库

根据类别的数量和在未缓存页面上显示此菜单的需要,我建议不要选择查看帮助程序的方式,而是直接在控制器中查询DB(正如Georg建议的那样)。只需将您的插槽连接到signal
GeorgRinger\News\Controller\CategoryController
listAction
。您将在那里获得所有类别(在参数
categories
中),并可以启动

SELECT COUNT(*) FROM sys_category_record_mm … GROUP BY uid_local

一次完成所有计数。然后,只需向返回的数组添加一个新键,并在模板中以该名称使用它。

根据类别的数量和在未缓存页面上显示此菜单的需要,我建议不要使用view helper方式,而是直接在控制器中查询DB(如Georg建议的)。只需将您的插槽连接到signal
GeorgRinger\News\Controller\CategoryController
listAction
。您将在那里获得所有类别(在参数
categories
中),并可以启动

SELECT COUNT(*) FROM sys_category_record_mm … GROUP BY uid_local

一次完成所有计数。然后,只需在返回的数组中添加一个新键,并在模板中以该名称使用它。

事实上,我找到了获取类别中新闻数量的方法。Thx和

我的ViewHelper

<?php

namespace HIT\huskytheme\ViewHelpers\News;

class CountCategoriesViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {

    /**
     * @var \GeorgRinger\News\Domain\Repository\NewsRepository
     * @inject
     */
    protected $newsRepository = null;


    /**
     * 
     * @param \GeorgRinger\News\Domain\Model\Category $category
     * @return string
     */
    public function render($category) {
        /* @var $demand \GeorgRinger\News\Domain\Model\Dto\NewsDemand */
        $demand = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\GeorgRinger\News\Domain\Model\Dto\NewsDemand::class);

        $demand->setCategories(array($category));
        $demand->setCategoryConjunction('and');
        $demand->setIncludeSubCategories(false);

        return count($this->newsRepository->findDemanded($demand));
    }
}

事实上,我找到了一种方法来获取分类中的新闻数量。Thx和

我的ViewHelper

<?php

namespace HIT\huskytheme\ViewHelpers\News;

class CountCategoriesViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {

    /**
     * @var \GeorgRinger\News\Domain\Repository\NewsRepository
     * @inject
     */
    protected $newsRepository = null;


    /**
     * 
     * @param \GeorgRinger\News\Domain\Model\Category $category
     * @return string
     */
    public function render($category) {
        /* @var $demand \GeorgRinger\News\Domain\Model\Dto\NewsDemand */
        $demand = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\GeorgRinger\News\Domain\Model\Dto\NewsDemand::class);

        $demand->setCategories(array($category));
        $demand->setCategoryConjunction('and');
        $demand->setIncludeSubCategories(false);

        return count($this->newsRepository->findDemanded($demand));
    }
}

您可以使用userFun对特定类别的新闻实体进行计数,为什么不使用该方法?原因-它的老派方法。最好为我的流体模板使用常规的ViewHelper。你可以使用userFun计算特定类别的新闻实体,为什么不使用该方法?原因-它的老派方法。最好为我的流体模板使用常规ViewHelper。重要的一点是,Oleg的代码不会中断(但返回0),因为它是一个有效的魔术方法调用,尽管没有用处。关于我的问题:为什么函数“findDemanded”有“$query->getQuerySettings()->SetPerrectStoragePage(false)”;但“CountRequired”没有,将StoragePid设置为“0”。因此,我可以正确地获取我的“FindDemand”列表,但不能通过“CountRequired”直接执行相同的操作。重要的是要提到,Oleg的代码没有中断(而是返回0),因为它是一个有效的神奇方法调用,尽管它没有用。关于我的问题:为什么函数“FindDemand”有“$query->getQuerySettings()->SetReserverStoragePage(false)”;“但是“CountRequired”没有并将StoragePid设置为“0”。因此,我可以正确地获取我的“FindDemand”列表,但不能通过“CountRequired”直接执行相同操作
...
                            <f:link.page title="{category.item.title}" class="current-item" pageUid="{settings.listPid}"
                                         additionalParams="{tx_news_pi1:{overwriteDemand:{categories: category.item.uid}}}">{category.item.title}
                                <span class="postnum">({s:news.countCategories(category: category.item)})</span>
                            </f:link.page>
...