将RealURL v2与JOIN语句一起使用(TYPO3)

时间:2018-01-14 20:17:53

标签: typo3 realurl

我需要在realurl中连接两个表来配置fixedPostVars。我发现的所有解决方案都适用于旧版本< 2 of realurl。

以下SQL语句返回想要的结果

SELECT 
CONCAT(DATE_FORMAT(FROM_UNIXTIME(tx_myext_domain_model_event.start_date), \'%d-%m-%Y\'),"-",tx_myext_domain_model_event.title,"-",tx_myext_domain_model_event.city) 
FROM 
    tx_myext_domain_model_eventannouncement
INNER JOIN
    tx_myext_domain_model_event
ON
    tx_myext_domain_model_eventannouncement.event = tx_myext_domain_model_event.uid
WHERE
    tx_myext_domain_model_eventannouncement.uid = 2
;

有没有办法在realurl配置中集成此SQL?我试过这个,但网址会产生https://example.com/.../detail/2/

'GETvar' => 'tx_myext_eventannouncement[eventannouncement]',
'lookUpTable' => [
    'table' => 'tx_myext_domain_model_eventannouncement',
    'id_field' => 'tx_myext_domain_model_eventannouncement.uid',
    'alias_field' => 'INNER JOIN tx_myext_domain_model_event ON tx_myext_domain_model_eventannouncement.event = tx_myext_domain_model_event.uid CONCAT(DATE_FORMAT(FROM_UNIXTIME(tx_myext_domain_model_event.start_date), \' % d -%m -%Y\'),"-",tx_myext_domain_model_event.title,"-",tx_myext_domain_model_event.city)',
    'addWhereClause' => ' AND tx_myext_domain_model_eventannouncement.deleted=0 AND tx_myext_domain_model_eventannouncement.hidden=0',
    'useUniqueCache' => true,
    'useUniqueCache_conf' => [
        'strtolower' => true,
        'spaceCharacter' => '-',
    ],
    'enable404forInvalidAlias' => true,
],

1 个答案:

答案 0 :(得分:1)

您有两个选项可以让RealURL通过此联接访问您的字段。

首先使用子查询 intead连接。

(SELECT DISTINCT
CONCAT(
DATE_FORMAT(FROM_UNIXTIME(tx_myext_domain_model_event.start_date), \'%d-%m-%Y\'),
"-",
tx_myext_domain_model_event.title,
"-",
tx_myext_domain_model_event.city) 
FROM tx_myext_domain_model_event
INNER JOIN
    tx_myext_domain_model_event
ON
    tx_myext_domain_model_eventannouncement.event = tx_myext_domain_model_event.uid) 
as alias_field

请注意,此代码段仅供参考,我没有机会为您测试。

第二个是创建视图

CREATE VIEW tx_myext_event_view AS 
    SELECT tx_myext_domain_model_eventannouncement.*,
CONCAT(DATE_FORMAT(FROM_UNIXTIME(tx_myext_domain_model_event.start_date), \'%d-%m-%Y\'),"-",tx_myext_domain_model_event.title,"-",tx_myext_domain_model_event.city) as alias_field
FROM 
    tx_myext_domain_model_eventannouncement
INNER JOIN
    tx_myext_domain_model_event
ON
    tx_myext_domain_model_eventannouncement.event = tx_myext_domain_model_event.uid

现在您可以将RealURL配置设置为:

'GETvar' => 'tx_myext_eventannouncement[eventannouncement]',
'lookUpTable' => [
    'table' => 'tx_myext_event_view',
    'id_field' => 'tx_myext_event_view.uid',
    'alias_field' => 'tx_myext_event_view.alias_field',
    'useUniqueCache' => true,
    'useUniqueCache_conf' => [
        'strtolower' => true,
        'spaceCharacter' => '-',
    ],
    'enable404forInvalidAlias' => true,
],

我会尝试使用子查询,因为在扩展中维护视图很棘手。然而,对于更复杂的逻辑,或者如果您有多个定义从不同条件的同一基础获取信息,它可能是更好的解决方案。