小编use*_*531的帖子

传递接口作为函数参数(PHP)?

我正在观看关于编码规则的Jeffs Laracast教程之一.

function signUp($subscription) 
{
    if ($subscription == 'monthly')
    {
        $this->createMonthlySubscription();
    }
    elseif ($subscription == 'forever')
    {
        $this->createForeverSubscription();
    }
 }
Run Code Online (Sandbox Code Playgroud)

他想在这里使用多态和接口.他将上面的代码更改为:

function signUp(Subscription $subscription)
{
    $subscription->create();
}
Run Code Online (Sandbox Code Playgroud)

我不明白他在这里做了什么.他是否将"Subscription"接口作为函数参数传递..?我以前从未在所有关于接口的教程中看到过这一点.

php polymorphism

4
推荐指数
1
解决办法
1317
查看次数

在前端按年份分组新闻(TYPO3,新闻系统)

我正在使用 TYPO3 9,新闻插件(新闻系统)。

我正在寻找一种按年份对新闻文章进行分组的方法,如下所示:

2019
--------
article 1
article 2
article 3
--------
2018
--------
article 1
article 2
...
Run Code Online (Sandbox Code Playgroud)

我找不到一个简单的解决方案,很难相信实现这一点的唯一方法是编辑 TYPO3 的源代码......

任何人都可以帮忙吗?

- - - - - - - - - - - - - 编辑

Bernd Wilke 建议的固定和工作代码:

<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
      xmlns:n="http://typo3.org/ns/GeorgRinger/News/ViewHelpers"
      data-namespace-typo3-fluid="true">
<f:layout name="General" />
<!--
    =====================
        Templates/News/List.html
-->

<f:section name="content">
    <!--TYPO3SEARCH_end-->
    <f:if condition="{news}">
        <f:then>
            <f:variable name="oldYear">2010</f:variable>
            <f:for each="{news}" as="newsItem" iteration="iterator">
                <f:variable name="currentYear"><f:format.date format="%Y">{newsItem.datetime}</f:format.date></f:variable>
                <f:if condition="{oldYear} < {currentYear}">
                    <hr />
                    <h3>{currentYear}</h3>
                    <hr />
                </f:if>
                <f:render partial="List/Item" arguments="{newsItem: …
Run Code Online (Sandbox Code Playgroud)

typo3 tx-news typo3-9.x

0
推荐指数
1
解决办法
372
查看次数

标签 统计

php ×1

polymorphism ×1

tx-news ×1

typo3 ×1

typo3-9.x ×1