Zend Framework

add 3 new methods to Zend_Uri_Http

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Trivial Trivial
  • Resolution: Fixed
  • Affects Version/s: 1.0.0 RC1
  • Fix Version/s: 1.10.0
  • Component/s: Zend_Uri
  • Labels:
    None

Description

  • method Zend_Uri_Http::getQueryAsArray()
    get the query params in an array
  • method Zend_Uri_Http::addQueryParams($params=array())
    which add or replace params in the query string
  • method Zend_Uri_Http::removeQueryParams($params=array())
    which remove params in the query string
/**
	 * Returns the query portion of the URL (after ?)
	 *
	 * @return array
	 */
	public function getQueryAsArray()
	{
		$queryParams = array();
		if($queryString = $this->getQuery()){
			$temp = explode('&', $queryString);
			foreach($temp as $param){
				list($key, $value) = explode('=', $param);
				$queryParams[$key] = $value;
			}
		}
        return $queryParams;;
	}
	
	
    /**
     * Add or replace params in the query string for the current URI, and return the old query 
     *
     * @param array $queryParams
     * @return string Old query string
     */
	public function addReplaceQuery($queryParams)
	{
		$queryParams = array_merge($this->getQueryAsArray(), $queryParams);
		return $this->setQuery($queryParams);
	}
	
    /**
     * Remove params in the query string for the current URI, and return the old query 
     *
     * @param array $queryParams
     * @return string Old query string
     */
	public function addReplaceQuery($queryParams)
	{
		$queryParams = array_diff($this->getQueryAsArray(), $queryParams);
		return $this->setQuery($queryParams);
	}

Activity

Hide
Shahar Evron added a comment -

This should be discussed for post 1.0 features

Show
Shahar Evron added a comment - This should be discussed for post 1.0 features
Hide
Bill Karwin added a comment -

Assign to Shahar.

Show
Bill Karwin added a comment - Assign to Shahar.
Hide
Stefan Gehrig added a comment -

closed in trunk (r19041).

Added

  • Zend_Uri_Http::getQueryAsArray()
  • Zend_Uri_Http::addReplaceQueryParameters(array $queryParams)
  • Zend_Uri_Http::removeQueryParameters(array $queryParamKeys)
Show
Stefan Gehrig added a comment - closed in trunk (r19041). Added
  • Zend_Uri_Http::getQueryAsArray()
  • Zend_Uri_Http::addReplaceQueryParameters(array $queryParams)
  • Zend_Uri_Http::removeQueryParameters(array $queryParamKeys)

People

Vote (3)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: