本文整理汇总了PHP中modX::findResource方法的典型用法代码示例。如果您正苦于以下问题:PHP modX::findResource方法的具体用法?PHP modX::findResource怎么用?PHP modX::findResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类modX
的用法示例。
在下文中一共展示了modX::findResource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _cleanResourceIdentifier
/**
* Cleans the resource identifier from the request params.
*
* @param string $identifier The raw identifier.
* @return string|integer The cleansed identifier.
*/
public function _cleanResourceIdentifier($identifier)
{
if (empty($identifier)) {
if ($this->modx->getOption('base_url', null, MODX_BASE_URL) !== strtok($_SERVER["REQUEST_URI"], '?')) {
$this->modx->sendRedirect($this->modx->getOption('site_url', null, MODX_SITE_URL), array('responseCode' => 'HTTP/1.1 301 Moved Permanently'));
}
$identifier = $this->modx->getOption('site_start', null, 1);
$this->modx->resourceMethod = 'id';
} elseif ($this->modx->getOption('friendly_urls', null, false) && $this->modx->resourceMethod == 'alias') {
$containerSuffix = trim($this->modx->getOption('container_suffix', null, ''));
$found = $this->modx->findResource($identifier);
if ($found === false && !empty($containerSuffix)) {
$suffixLen = strlen($containerSuffix);
$identifierLen = strlen($identifier);
if (substr($identifier, $identifierLen - $suffixLen) === $containerSuffix) {
$identifier = substr($identifier, 0, $identifierLen - $suffixLen);
$found = $this->modx->findResource($identifier);
} else {
$identifier = "{$identifier}{$containerSuffix}";
$found = $this->modx->findResource("{$identifier}{$containerSuffix}");
}
if ($found) {
$parameters = $this->getParameters();
unset($parameters[$this->modx->getOption('request_param_alias')]);
$url = $this->modx->makeUrl($found, $this->modx->context->get('key'), $parameters, 'full');
$this->modx->sendRedirect($url, array('responseCode' => 'HTTP/1.1 301 Moved Permanently'));
}
$this->modx->resourceMethod = 'alias';
} elseif ((int) $this->modx->getOption('site_start', null, 1) === $found) {
$parameters = $this->getParameters();
unset($parameters[$this->modx->getOption('request_param_alias')]);
$url = $this->modx->makeUrl($this->modx->getOption('site_start', null, 1), $this->modx->context->get('key'), $parameters, 'full');
$this->modx->sendRedirect($url, array('responseCode' => 'HTTP/1.1 301 Moved Permanently'));
} else {
if ($this->modx->getOption('friendly_urls_strict', null, false)) {
$requestUri = $_SERVER['REQUEST_URI'];
$qsPos = strpos($requestUri, '?');
if ($qsPos !== false) {
$requestUri = substr($requestUri, 0, $qsPos);
}
$fullId = $this->modx->getOption('base_url', null, MODX_BASE_URL) . $identifier;
$requestUri = urldecode($requestUri);
if ($fullId !== $requestUri && strpos($requestUri, $fullId) !== 0) {
$parameters = $this->getParameters();
unset($parameters[$this->modx->getOption('request_param_alias')]);
$url = $this->modx->makeUrl($found, $this->modx->context->get('key'), $parameters, 'full');
$this->modx->sendRedirect($url, array('responseCode' => 'HTTP/1.1 301 Moved Permanently'));
}
}
$this->modx->resourceMethod = 'alias';
}
} else {
$this->modx->resourceMethod = 'id';
}
return $identifier;
}
示例2: findResource
/**
* @param $uri
* @param string $context
*
* @return bool|int|mixed
*/
public function findResource($uri, $context = '')
{
return $this->modx->findResource($uri, $context);
}