Commit ab42ab2d by Qiang Xue

url wip

parent 379fddfe
......@@ -19,7 +19,70 @@ use \yii\base\Component;
*/
class UrlManager extends Component
{
/**
* @var array the URL rules (pattern=>route).
*/
public $rules = array();
/**
* @var string the URL suffix used when in 'path' format.
* For example, ".html" can be used so that the URL looks like pointing to a static HTML page. Defaults to empty.
*/
public $urlSuffix = '';
/**
* @var boolean whether to show entry script name in the constructed URL. Defaults to true.
*/
public $showScriptName = true;
/**
* @var boolean whether to append GET parameters to the path info part. Defaults to true.
* This property is only effective when {@link urlFormat} is 'path' and is mainly used when
* creating URLs. When it is true, GET parameters will be appended to the path info and
* separate from each other using slashes. If this is false, GET parameters will be in query part.
*/
public $appendParams = true;
/**
* @var string the GET variable name for route. Defaults to 'r'.
*/
public $routeVar = 'r';
/**
* @var boolean whether routes are case-sensitive. Defaults to true. By setting this to false,
* the route in the incoming request will be turned to lower case first before further processing.
* As a result, you should follow the convention that you use lower case when specifying
* controller mapping ({@link CWebApplication::controllerMap}) and action mapping
* ({@link CController::actions}). Also, the directory names for organizing controllers should
* be in lower case.
*/
public $caseSensitive = true;
/**
* @var boolean whether the GET parameter values should match the corresponding
* sub-patterns in a rule before using it to create a URL. Defaults to false, meaning
* a rule will be used for creating a URL only if its route and parameter names match the given ones.
* If this property is set true, then the given parameter values must also match the corresponding
* parameter sub-patterns. Note that setting this property to true will degrade performance.
* @since 1.1.0
*/
public $matchValue = false;
/**
* @var string the ID of the cache application component that is used to cache the parsed URL rules.
* Defaults to 'cache' which refers to the primary cache application component.
* Set this property to false if you want to disable caching URL rules.
*/
public $cacheID = 'cache';
/**
* @var boolean whether to enable strict URL parsing.
* This property is only effective when {@link urlFormat} is 'path'.
* If it is set true, then an incoming URL must match one of the {@link rules URL rules}.
* Otherwise, it will be treated as an invalid request and trigger a 404 HTTP exception.
* Defaults to false.
*/
public $useStrictParsing = false;
/**
* @var string the class name or path alias for the URL rule instances. Defaults to 'CUrlRule'.
* If you change this to something else, please make sure that the new class must extend from
* {@link CBaseUrlRule} and have the same constructor signature as {@link CUrlRule}.
* It must also be serializable and autoloadable.
* @since 1.1.8
*/
public $urlRuleClass = 'CUrlRule';
/**
* Initializes the application component.
......@@ -44,10 +107,11 @@ class UrlManager extends Component
*/
public function parseUrl($request)
{
if(isset($_GET[$this->routeVar]))
if (isset($_GET[$this->routeVar])) {
return $_GET[$this->routeVar];
else
} else {
return '';
}
}
public function createUrl($route, $params = array(), $ampersand = '&')
......
......@@ -13,6 +13,11 @@ use yii\base\Object;
/**
* UrlManager manages the URLs of Yii applications.
* array(
* 'pattern' => 'post/<id:\d+>',
* 'route' => 'post/view',
* 'params' => array('id' => 1),
* )
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
......@@ -20,76 +25,29 @@ use yii\base\Object;
class UrlRule extends Object
{
/**
* @var string the URL suffix used for this rule.
* For example, ".html" can be used so that the URL looks like pointing to a static HTML page.
* Defaults to null, meaning using the value of {@link CUrlManager::urlSuffix}.
*/
public $urlSuffix;
/**
* @var boolean whether the rule is case sensitive. Defaults to null, meaning
* using the value of {@link CUrlManager::caseSensitive}.
* @var string regular expression used to parse a URL
*/
public $caseSensitive;
public $pattern;
/**
* @var array the default GET parameters (name=>value) that this rule provides.
* When this rule is used to parse the incoming request, the values declared in this property
* will be injected into $_GET.
*/
public $defaultParams = array();
/**
* @var boolean whether the GET parameter values should match the corresponding
* sub-patterns in the rule when creating a URL. Defaults to null, meaning using the value
* of {@link CUrlManager::matchValue}. When this property is false, it means
* a rule will be used for creating a URL if its route and parameter names match the given ones.
* If this property is set true, then the given parameter values must also match the corresponding
* parameter sub-patterns. Note that setting this property to true will degrade performance.
* @since 1.1.0
*/
public $matchValue;
/**
* @var string the HTTP verb (e.g. GET, POST, DELETE) that this rule should match.
* If this rule can match multiple verbs, please separate them with commas.
* If this property is not set, the rule can match any verb.
* Note that this property is only used when parsing a request. It is ignored for URL creation.
* @since 1.1.7
*/
public $verb;
/**
* @var boolean whether this rule is only used for request parsing.
* Defaults to false, meaning the rule is used for both URL parsing and creation.
* @since 1.1.7
*/
public $parsingOnly = false;
/**
* @var string the controller/action pair
*/
public $route;
/**
* @var array the mapping from route param name to token name (e.g. _r1=><1>)
*/
public $references = array();
/**
* @var string the pattern used to match route
*/
public $routePattern;
/**
* @var string regular expression used to parse a URL
*/
public $pattern;
/**
* @var string template used to construct a URL
*/
public $template;
/**
* @var array list of parameters (name=>regular expression)
*/
public $params = array();
/**
* @var boolean whether the URL allows additional parameters at the end of the path info.
*/
public $append;
/**
* @var boolean whether host info should be considered for this rule
* @var string the route to the controller action
*/
public $hasHostInfo;
public $route;
public function createUrl($route, $params, $ampersand)
{
}
public function parse($path)
{
$route = '';
$params = array();
return array($route, $params);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment