[TOC]
## 構造Web頁面URL createWebUrl()
**例如**
~~~
{php echo $this->createWebUrl('goods', array('op'=>'edit'));}
~~~
**生成**
~~~
./index.php?c=site&a=entry&op=edit&do=goods&m=hx_apicms
~~~
**原型**
~~~
protected function createWebUrl($do, $query = array()) {
$query['do'] = $do;
$query['m'] = strtolower($this->modulename);
return wurl('site/entry', $query);
}
~~~
> strtolower() 函數把字符串轉換為小寫
~~~
function wurl($segment, $params = array()) {
list($controller, $action, $do) = explode('/', $segment);
$url = './index.php?';
if (!empty($controller)) {
$url .= "c={$controller}&";
}
if (!empty($action)) {
$url .= "a={$action}&";
}
if (!empty($do)) {``
$url .= "do={$do}&";
}
if (!empty($params)) {
$queryString = http_build_query($params, '', '&');
$url .= $queryString;
}
return $url;
}
~~~
> explode() 函數把字符串打散為數組
> http_build_query — 生成 URL-encode 之后的請求字符串
| 參數 | |
| -- | -- |
| $do | string |要進入的操作名稱對應當前模塊的 doWebXxx 中的 Xxx|
|$query |array |附加的查詢參數 |
| 返回值 | |
| -- | -- |
| string | Url |