Changeset 1539 for branches/3.0/framework/Web/TUrlMapping.php
- Timestamp:
- 12/02/2006 01:20:40 PM (2 years ago)
- Files:
-
- 1 modified
-
branches/3.0/framework/Web/TUrlMapping.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/3.0/framework/Web/TUrlMapping.php
r1511 r1539 11 11 */ 12 12 13 Prado::using('System.Web.TUrlManager'); 14 13 15 /** 14 16 * TUrlMapping Class … … 18 20 * before a service is initialized, thus this module should be configured 19 21 * globally in the <tt>application.xml</tt> file and before any services. 20 *21 * The mapping format is as follows.22 22 * <code> 23 23 * <module id="friendly-url" class="System.Web.TUrlMapping"> … … 26 26 * <url ServiceParameter="Posts.ListPost" pattern="category/{cat}/?" parameters.cat="\d+" /> 27 27 * </module> 28 * <module id="request" class="THttpRequest" UrlManager="friendly-url" /> 28 29 * </code> 29 30 * … … 38 39 * The mapping can be load from an external file by specifying a configuration 39 40 * file using the {@link setConfigFile ConfigFile} property. 41 * 42 * Since TUrlMapping is a URL manager extending from {@link TUrlManager}, 43 * you may override {@link TUrlManager::constructUrl} to support your pattern-based 44 * URL scheme. 40 45 * 41 46 * @author Wei Zhuo <weizhuo[at]gmail[dot]com> … … 44 49 * @since 3.0.5 45 50 */ 46 class TUrlMapping extends T Module51 class TUrlMapping extends TUrlManager 47 52 { 48 53 /** 54 * File extension of external configuration file 55 */ 56 const CONFIG_FILE_EXT='.xml'; 57 /** 49 58 * @var string default pattern class. 50 59 */ … … 58 67 */ 59 68 private $_matched; 60 /**61 * File extension of external configuration file62 */63 const CONFIG_FILE_EXT='.xml';64 69 /** 65 70 * @var string external configuration file … … 75 80 public function init($xml) 76 81 { 82 parent::init($xml); 77 83 if($this->getRequest()->getRequestResolved()) 78 84 throw new TConfigurationException('urlpath_dispatch_module_must_be_global'); … … 80 86 $this->loadConfigFile(); 81 87 $this->loadUrlMappings($xml); 82 $this->resolveMappings();83 88 } 84 89 … … 143 148 144 149 /** 145 * Using the request URL path, find the first matching pattern. If found 146 * the matched pattern parameters are used in the Request object. 147 */ 148 protected function resolveMappings() 150 * Parses the request URL and returns an array of input parameters. 151 * This method overrides the parent implementation. 152 * The input parameters do not include GET and POST variables. 153 * This method uses the request URL path to find the first matching pattern. If found 154 * the matched pattern parameters are used to return as the input parameters. 155 * @return array list of input parameters 156 */ 157 public function parseUrl() 149 158 { 150 159 $url = $this->getRequest()->getUrl(); … … 154 163 if(count($matches) > 0) 155 164 { 165 $this->_matched=$pattern; 156 166 $this->changeServiceParameters($pattern); 157 $this->initializeRequestParameters($matches); 158 $this->_matched=$pattern; 159 break; 167 $params=array(); 168 foreach($matches as $key=>$value) 169 if(is_string($key)) 170 $params[$key]=$value; 171 return $params; 160 172 } 161 173 } 174 return array(); 162 175 } 163 176 … … 168 181 { 169 182 return $this->_matched; 170 }171 172 /**173 * @param array initialize the Request with matched parameters.174 */175 protected function initializeRequestParameters($matches)176 {177 $request = $this->getRequest();178 foreach($matches as $k => $v)179 {180 if(!is_int($k))181 $request->add($k,$v);182 }183 183 } 184 184
