本文整理汇总了PHP中CUrlManager类的典型用法代码示例。如果您正苦于以下问题:PHP CUrlManager类的具体用法?PHP CUrlManager怎么用?PHP CUrlManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CUrlManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createUrl
/**
*
* @see CUrlManager
*
* Constructs a URL.
* @param string the controller and the action (e.g. article/read)
* @param array list of GET parameters (name=>value). Both the name and value will be URL-encoded.
* If the name is '#', the corresponding value will be treated as an anchor
* and will be appended at the end of the URL. This anchor feature has been available since version 1.0.1.
* @param string the token separating name-value pairs in the URL. Defaults to '&'.
* @return string the constructed URL
*/
public function createUrl($route, $params = array(), $ampersand = '&')
{
// We added this by default to all links to show
// Content based on language - Add only when not excplicity set
if (!isset($params['lang'])) {
$params['lang'] = Yii::app()->language;
}
if (isset($params['lang']) && $params['lang'] === false) {
unset($params['lang']);
}
// Use parent to finish url construction
return parent::createUrl($route, $params, $ampersand);
}
示例2: createUrl
public function createUrl($route, $params = array(), $ampersand = '&')
{
$route = trim($route, '/');
//for admin and admin/*
$parts = explode('/', $route);
//do not mess with gii
if ($parts[0] == 'gii') {
return parent::createUrl($route, $params, $ampersand);
}
// ignore defaultController
if (Yii::app()->hasModule($parts[0]) && isset($parts[1]) && $parts[1] == Yii::app()->getModule($parts[0])->defaultController) {
unset($parts[1]);
$route = implode('/', $parts);
}
if (substr(Yii::app()->getRequest()->pathInfo, 0, 6) == 'admin/' || Yii::app()->getRequest()->pathInfo == 'admin') {
$route = 'admin/' . trim($route, '/');
}
$url = parent::createUrl($route, $params, $ampersand);
if (Settings::get('SEO', 'slugs_enabled')) {
//handle slugs here
if ($slug = Slug::getSlug(preg_replace('/' . trim(Yii::app()->baseUrl, '/') . '/', '', $url, 1))) {
//if (Settings::get('SEO','externalSlug')
$url = $slug;
$url = Yii::app()->baseUrl . '/' . $url;
}
}
return $url;
}
示例3: createUrl
public function createUrl($route, $params = array(), $ampersand = '&')
{
if (empty($params['language']) && Yii::app()->language !== 'ru') {
$params['language'] = Yii::app()->language;
}
if (!isset(Yii::app()->controller->module->id)) {
if (!strstr($route, 'register')) {
if (isset($_POST['city'])) {
$cookie = new CHttpCookie('city', $_POST['city']);
Yii::app()->request->cookies['city'] = $cookie;
$cookie->expire = time() + 3600;
$c = City::model()->localized('ru')->findByPk($_POST['city'])->name;
$params['city'] = Settings::toLatin($c);
} elseif (isset(Yii::app()->request->cookies['city'])) {
$c = City::model()->localized('ru')->findByPk(Yii::app()->request->cookies['city']->value)->name;
$params['city'] = Settings::toLatin($c);
} else {
unset($params['city']);
}
} else {
unset($params['city']);
}
}
/*if (!strstr($route,'/')) {
$route = '/cat/'.$route;
}*/
return Yii::app()->request->hostInfo . parent::createUrl($route, $params, $ampersand);
}
示例4: createUrl
public function createUrl($route, $params = array(), $ampersand = '&')
{
if (isset($params[$this->languageParam])) {
$language = $params[$this->languageParam];
$forceLanguage = true;
unset($params[$this->languageParam]);
} else {
$language = Yii::app()->language;
$forceLanguage = false;
}
$url = parent::createUrl($route, $params, $ampersand);
$request = Yii::app()->request;
if (!$forceLanguage && !$request->redirectDefault && $language === $request->getDefaultLanguage()) {
return $url;
}
$key = array_search($language, $request->languages);
if (is_string($key)) {
$language = $key;
}
if (($baseUrl = $this->getBaseUrl()) === '') {
return '/' . $language . $url;
} else {
return strtr($url, array($baseUrl => $baseUrl . '/' . $language));
}
}
示例5: processRules
protected function processRules()
{
$rules = array();
$method = strtolower(Yii::app()->getRequest()->getRequestType());
//transform method's rules keys to lowercase
$this->rules = array_combine(array_map(array($this, '__atToLowerCase'), array_keys($this->rules)), array_values($this->rules));
//check if it has an index the same as the request type and if it does add its rules
if (key_exists("@{$method}", $this->rules)) {
$rules = $this->rules["@{$method}"];
}
//add the default rules
if (is_array($rules)) {
foreach ($this->rules as $k => $rule) {
if (substr($k, 0, 1) !== '@') {
$rules[$k] = $rule;
}
}
} elseif (is_string($rules)) {
$rules = array("." => $rules);
}
//override the existing rules with only those that matche with the request type
$this->rules = $rules;
//disable cache that causes it to load wrong rules
//cant use it as its defined as a constant and not able to change to use method's specific cache
$this->cacheID = false;
parent::processRules();
}
示例6: createUrl
public function createUrl($route, $params = array(), $ampersand = '&')
{
if (!isset($params['language'])) {
$params['language'] = Yii::app()->language;
}
return parent::createUrl($route, $params, $ampersand);
}
示例7: createLangUrl
public function createLangUrl($language, $ampersand = '&')
{
$route = Yii::app()->controller->route;
$params = $_GET;
unset($params[$this->routeVar]);
$params[$this->langParam] = $language;
return parent::createUrl($route, $params, $ampersand);
}
示例8: parseUrl
public function parseUrl($request)
{
$route = parent::parseUrl($request);
if (substr_count($route, '-') > 0) {
$route = lcfirst(str_replace(' ', '', ucwords(str_replace('-', ' ', $route))));
}
return $route;
}
示例9: createUrl
public function createUrl($route, $params = array(), $ampersand = '&')
{
$url = parent::createUrl($route, $params, $ampersand);
if ($this->getFrontendMode()) {
$baseUrl = $this->getBaseUrl();
return mb_substr($url, mb_strlen($baseUrl));
}
return $url;
}
示例10: processRules
/**
* Build the rules from the DB
*/
protected function processRules()
{
if (($this->rules = Yii::app()->cache->get('customurlrules')) === false) {
// Site Rules
$this->rules = array('project/<id:\\d+>/<alias>' => 'site/projects/viewproject', 'issue/<id:\\d+>/<alias>' => 'site/tickets/viewticket', 'issues/<type:(priority|version|fixedin|type|status|category|project|milestone)>/<id:\\d+>/<alias>' => 'site/tickets/filterissues', 'issues/<type:(priority|version|fixedin|type|status|category|project|milestone)>/<id:\\d+>/<alias>/<rss:\\w+>' => 'site/tickets/filterissues', 'issues/tag/<tag>' => 'site/tickets/filterissuesbytag', 'wiki/<id:\\d+>/<alias>' => 'site/wiki/viewpage', 'wiki/<id:\\d+>/<alias>/<revisionid:\\d+>' => 'site/wiki/viewpagerevision', '' => 'site/index/index', '<_c:([a-zA-z0-9-]+)>' => 'site/<_c>/index', '<_c:([a-zA-z0-9-]+)>/<_a:([a-zA-z0-9-]+)>' => 'site/<_c>/<_a>', '<_c:([a-zA-z0-9-]+)>/<_a:([a-zA-z0-9-]+)>//*' => 'site/<_c>/<_a>/');
Yii::app()->cache->set('customurlrules', $this->rules);
}
// Run parent
parent::processRules();
}
示例11: createUrl
public function createUrl($route,$params=array(),$ampersand='&')
{
if (!isset($params['language'])) {
if (Yii::app()->user->hasState('language'))
Yii::app()->language = Yii::app()->user->getState('language');
else if(isset(Yii::app()->request->cookies['language']))
Yii::app()->language = Yii::app()->request->cookies['language']->value;
$params['language']=Yii::app()->language;
}
return parent::createUrl($route, $params, $ampersand);
}
示例12: createUrl
public function createUrl($route, $params = array(), $ampersand = '&')
{
if ($route != 'min/serve' && $route != 'site/uploadimage') {
$langs = Lang::getActiveLangs();
$countLangs = count($langs);
if (!isFree() && empty($params['lang']) && ($countLangs > 1 || $countLangs == 1 && param('useLangPrefixIfOneLang'))) {
$params['lang'] = Yii::app()->language;
}
}
return parent::createUrl($route, $params, $ampersand);
}
示例13: createUrl
/**
* Create url based on current language.
* @param mixed $route
* @param array $params
* @param string $ampersand
* @param boolean $respectLang
* @access public
* @return string
*/
public function createUrl($route, $params = array(), $ampersand = '&', $respectLang = true)
{
$result = parent::createUrl($route, $params, $ampersand);
if ($respectLang === true) {
$langPrefix = Yii::app()->languageManager->getUrlPrefix();
if ($langPrefix) {
$result = '/' . $langPrefix . $result;
}
}
return $result;
}
示例14: createUrl
/**
* @inheritDoc
*/
public function createUrl($route, $params = array(), $ampersand = '&')
{
$oldUrlSuffix = $this->urlSuffix;
if (isset($params['_ext'])) {
$this->urlSuffix = '.' . $params['_ext'];
unset($params['_ext']);
}
$url = parent::createUrl($route, $params, $ampersand);
$this->urlSuffix = $oldUrlSuffix;
return $url;
}
示例15: parseUrl
public function parseUrl($request)
{
$searchPaths = array($request->pathInfo);
// Also search for paths that end with the wildcard "*" (e.g. with news details)
if ($lastPathSeparatorPos = strrpos($request->pathInfo, '/')) {
$searchPaths[] = substr($request->pathInfo, 0, $lastPathSeparatorPos + 1) . '*';
}
$page = CmsPage::model()->findByAttributes(array('path' => $searchPaths));
if ($page !== null) {
return 'cms/page/default/id/' . $page->id;
}
return parent::parseUrl($request);
}