【问题标题】:Preserve arguments in uri builder在 uri builder 中保留参数
【发布时间】:2014-09-04 21:44:25
【问题描述】:

假设我有一个带有 URI 的页面:

 http://mydomain.loc/index.php?id=123&by=name&dir=desc

并且需要向它添加/更新/删除一些其他参数(我们将其命名为 offset),所以毕竟它将是:

 http://mydomain.loc/index.php?id=123&by=name&dir=desc&offset=321

不幸的是,像这样用uriBuilder 建立新链接时

$uriBuilder = $this->uriBuilder;
$uri = $uriBuilder->setArguments(array('offset' => 321))->build();

我只得到index.php?id=123&offset=321(不再有bydir 参数......)

如何强制uriBuilder 保留这些论点? (GeneralUtility::_GP(*) 手动重写参数是不可能的,因为它们在理论上是未知

$_GET 数组也不好,因为我正在使用 RealURL

【问题讨论】:

    标签: typo3 extbase typo3-6.1.x realurl uribuilder


    【解决方案1】:

    uriBuilder 有一个setAddQueryString 方法,它完全符合您的要求。它将当前查询字符串合并到参数中:

    $uri = $this->uriBuilder->setArguments(array('offset' => 321))->setAddQueryString(TRUE)->build();
    

    这里作为参考是从TYPO3核心的实际类中复制出来的方法:

    /**
     * If set, the current query parameters will be merged with $this->arguments. Defaults to FALSE.
     *
     * @param boolean $addQueryString
     * @return \TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder the current UriBuilder to allow method chaining
     * @api
     * @see TSref/typolink.addQueryString
     */
    public function setAddQueryString($addQueryString) {
        $this->addQueryString = (boolean) $addQueryString;
        return $this;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-13
      • 1970-01-01
      • 1970-01-01
      • 2010-10-04
      • 1970-01-01
      • 1970-01-01
      • 2015-06-28
      • 1970-01-01
      相关资源
      最近更新 更多