Frontend\Core\Engine\Model::addURLParameters PHP Method

addURLParameters() public static method

Add parameters to an URL
public static addURLParameters ( string $url, array $parameters ) : string
$url string The URL to append the parameters too.
$parameters array The parameters as key-value-pairs.
return string
    public static function addURLParameters($url, array $parameters)
    {
        $url = (string) $url;
        if (empty($parameters)) {
            return $url;
        }
        $chunks = explode('#', $url, 2);
        $hash = '';
        if (isset($chunks[1])) {
            $url = $chunks[0];
            $hash = '#' . $chunks[1];
        }
        // build query string
        $queryString = http_build_query($parameters, null, '&', PHP_QUERY_RFC3986);
        if (mb_strpos($url, '?') !== false) {
            $url .= '&' . $queryString . $hash;
        } else {
            $url .= '?' . $queryString . $hash;
        }
        return $url;
    }

Usage Example

Example #1
0
 /**
  * Set the image for the feed.
  *
  * @param string $url         URL of the image.
  * @param string $title       Title of the image.
  * @param string $link        Link of the image.
  * @param int    $width       Width of the image.
  * @param int    $height      Height of the image.
  * @param string $description Description of the image.
  */
 public function setImage($url, $title, $link, $width = null, $height = null, $description = null)
 {
     // add UTM-parameters
     $link = Model::addURLParameters($link, array('utm_source' => 'feed', 'utm_medium' => 'rss', 'utm_campaign' => CommonUri::getUrl($this->getTitle())));
     // call the parent
     parent::setImage($url, $title, $link, $width, $height, $description);
 }
All Usage Examples Of Frontend\Core\Engine\Model::addURLParameters