简体   繁体   English

如何在realurl中省略空(可选)段?

[英]How to omit empty (optional) segment in realurl?

Currently I'm trying to create nice looking URL's for my custom extension. 目前,我正在尝试为自定义扩展名创建美观的URL。

I am using a plugin on page "Products" (uid: 3) to list all categories. 我在页面“产品”(uid:3)上使用插件列出所有类别。

For example there are the following categories: 例如,有以下类别:

  • Men 男人
    • Shirts 衬衫
    • Sweatshirts 运动衫
  • Women 妇女
    • Shoes
    • Dresses 连衣裙

I'd like to have these corresponding URL's: 我想要这些对应的URL:

www.mydomain.com/products/men.html www.mydomain.com/products/men.html

www.mydomain.com/products/men/shirts.html www.mydomain.com/products/men/shirts.html

This is, what I get: 这就是我得到的:

www.mydomain.com/products//men.html www.mydomain.com/products//men.html

www.mydomain.com/products/men/shirts.html www.mydomain.com/products/men/shirts.html

The category "Men" on the first Level does not have a parent category, so this segment remains empty. 第一层的“男人”类别没有父类别,因此此细分受众群保持空白。 As soon as there is a parent category, everything is fine. 一旦有了父类别,一切都很好。

TYPO3 Version: 7.6.15 TYPO3版本:7.6.15

realurl Version: 2.1.6 realurl版本:2.1.6

This is my current configuration for fixedPostVars: 这是我当前的fixedPostVars配置:

'fixedPostVars' => array ( 
// EXT: productsDb start           
'productsDbConfiguration' => array(
    array(
        'GETvar' => 'tx_productsdb_categories[action]',
        'valueMap' => array(
        ),
        'noMatch' => 'bypass'
    ),
    array(
        'GETvar' => 'tx_productsdb_categories[controller]',
        'valueMap' => array(
        ),
        'noMatch' => 'bypass'
    ),
    array(
        'GETvar' => 'tx_productsdb_categories[parent]',
        'lookUpTable' => array(
            'table' => 'tx_productsdb_domain_model_category',
            'id_field' => 'uid',
            'alias_field' => 'title',
            'addWhereClause' => ' AND NOT deleted',
            'useUniqueCache' => 1,
            'useUniqueCache_conf' => array(
                'strtolower' => 1,
                'spaceCharacter' => '-'
            ),
            'languageGetVar' => 'L',
            'languageExceptionUids' => '',
            'languageField' => 'sys_language_uid',
            'transOrigPointerField' => 'l10n_parent',
            //'autoUpdate' => 1,
            //'expireDays' => 180,
        ),
       // 'valueDefault' => '',
    ),
    array(
        'GETvar' => 'tx_productsdb_categories[category]',
        'lookUpTable' => array(
            'table' => 'tx_productsdb_domain_model_category',
            'id_field' => 'uid',
            'alias_field' => 'title',
            'addWhereClause' => ' AND NOT deleted',
            'useUniqueCache' => 1,
            'useUniqueCache_conf' => array(
                'strtolower' => 1,
                'spaceCharacter' => '-'
            ),
            'languageGetVar' => 'L',
            'languageExceptionUids' => '',
            'languageField' => 'sys_language_uid',
            'transOrigPointerField' => 'l10n_parent',
            //'autoUpdate' => 1,
            //'expireDays' => 180,
        )
    ),
),
'3' => 'productsDbConfiguration',
// EXT: productsdb end

),

So, here is my question: Is there a way and what do I need to do, to skip an optional path segment, if it is empty? 所以,这是我的问题:如果有可选路径段为空,是否有一种方法和我该怎么做才能跳过?

Thanks in advance for having a look at it. 在此先感谢您的关注。

here's the code I used for the realurl encodeSpURL_postProc hook: 这是我用于realurl encodeSpURL_postProc挂钩的代码:

public function encodeUrl(&$params) {
    $originalParameters = $params['pObj']->getOriginalUrlParameters();

    if(array_key_exists('tx_productsdb_categories[category]', $originalParameters)===TRUE) {
        if (strpos($params['URL'], '//')) {
            $encodedSegments = explode('/', $params['URL']);
            $modifiedSegments = array_filter($encodedSegments, 'strlen');
            $params['URL'] = implode('/', $modifiedSegments);
        }
    }
}

let me know, if you got any other ideas for improvement. 让我知道,如果您还有其他需要改进的想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM