本文整理汇总了PHP中Cx\Core\Routing\Url::isVirtualLanguageDirsActive方法的典型用法代码示例。如果您正苦于以下问题:PHP Url::isVirtualLanguageDirsActive方法的具体用法?PHP Url::isVirtualLanguageDirsActive怎么用?PHP Url::isVirtualLanguageDirsActive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cx\Core\Routing\Url
的用法示例。
在下文中一共展示了Url::isVirtualLanguageDirsActive方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* @prePersist
* @onFlush
*/
public function validate()
{
// Slug must be unique per language and level of a branch (of the node tree)
$slugs = array();
foreach ($this->getNode()->getParent()->getChildren() as $child) {
// if virtual lang dirs are deactivated
if (!\Cx\Core\Routing\Url::isVirtualLanguageDirsActive()) {
if ($this->getLang() == 0) {
// check default language for the same slug
$page = $child->getPage(\FWLanguage::getDefaultLangId());
} else {
// check lang '0' for the same slug
$page = $child->getPage(0);
}
if ($page && $page !== $this) {
$slugs[] = strtolower($page->getSlug());
}
}
// check pages of the same language
$page = $child->getPage($this->getLang());
if ($page && $page !== $this) {
$slugs[] = strtolower($page->getSlug());
}
}
while ($this->getSlug() == '' || in_array(strtolower($this->getSlug()), $slugs)) {
$this->nextSlug();
}
// Alias slugs must not be equal to an existing file or folder
if ($this->getType() == self::TYPE_ALIAS) {
$invalidAliasNames = array('admin', 'cache', 'cadmin', 'config', 'core', 'core_modules', 'customizing', 'feed', 'images', 'installer', 'lang', 'lib', 'media', 'model', 'modules', 'themes', 'tmp', 'update', 'webcam', 'favicon.ico');
foreach (\FWLanguage::getActiveFrontendLanguages() as $id => $lang) {
$invalidAliasNames[] = $lang['lang'];
}
if (in_array($this->getSlug(), $invalidAliasNames)) {
$lang = \Env::get('lang');
throw new PageException('Cannot use name of existing files, folders or languages as alias.', $lang['TXT_CORE_CANNOT_USE_AS_ALIAS']);
}
}
//workaround, this method is regenerated each time
parent::validate();
}
示例2: resolvePage
//.........这里部分代码省略.........
// in case $langId is really the requested CMD then we will have to set the
// resolved language back to our original language $this->lang.
if (!$targetPage) {
$targetPage = $this->pageRepo->findOneBymoduleCmdLang($module, $cmd . '_' . $langId, $this->lang);
if ($targetPage) {
$langId = $this->lang;
}
}
// try to retrieve a module page that uses only an ID as CMD.
// lets try to find the module by using the INT in $langId as CMD.
// in case $langId is really the requested CMD then we will have to set the
// resolved language back to our original language $this->lang.
if (!$targetPage) {
$targetPage = $this->pageRepo->findOneByModuleCmdLang($module, $langId, $this->lang);
$langId = $this->lang;
}
// revert to default language if we could not retrieve the specified langauge by the redirection.
// so lets try to load the redirection of the current language
if (!$targetPage) {
if ($langId != 0) {
//make sure we weren't already retrieving the default language
$targetPage = $this->pageRepo->findOneByModuleCmdLang($module, $cmd, $this->lang);
$langId = $this->lang;
}
}
}
//check whether we have a page now.
if (!$targetPage) {
$this->page = null;
return;
}
// the redirection page is located within a different language.
// therefore, we must set $this->lang to the target's language of the redirection.
// this is required because we will next try to resolve the redirection target
if ($langId != $this->lang) {
$this->lang = $langId;
$this->url->setLangDir(\FWLanguage::getLanguageCodeById($langId));
$this->pathOffset = ASCMS_INSTANCE_OFFSET;
}
$targetPath = substr($targetPage->getPath(), 1);
$this->url->setTargetPath($targetPath . $qs);
$this->url->setPath($targetPath . $qs);
$this->isRedirection = true;
$this->resolvePage(true);
} else {
//external target - redirect via HTTP 302
if (\FWValidator::isUri($target)) {
$this->headers['Location'] = $target;
$emptyString = '';
\Env::set('Resolver', $this);
\Env::set('Page', $this->page);
\Env::get('cx')->getComponent('Cache')->postFinalize($emptyString);
header('Location: ' . $target);
exit;
} else {
if ($target[0] == '/') {
$target = substr($target, 1);
}
$langDir = '';
if (!file_exists(ASCMS_INSTANCE_PATH . ASCMS_INSTANCE_OFFSET . '/' . $target)) {
$langCode = '';
if (\Cx\Core\Routing\Url::isVirtualLanguageDirsActive()) {
$langCode = \FWLanguage::getLanguageCodeById($this->lang);
}
if (!empty($langCode)) {
$langDir = '/' . $langCode;
}
}
$target = ASCMS_INSTANCE_OFFSET . $langDir . '/' . $target;
$this->headers['Location'] = $target;
$emptyString = '';
\Env::set('Resolver', $this);
\Env::set('Page', $this->page);
\Env::get('cx')->getComponent('Cache')->postFinalize($emptyString);
header('Location: ' . $target);
exit;
}
}
}
//if we followed one or more redirections, the user shall be redirected by 302.
if ($this->isRedirection && !$this->forceInternalRedirection) {
$params = $this->url->getSuggestedParams();
$target = $this->page->getURL($this->pathOffset, array());
$target->setParams($params);
$this->headers['Location'] = $target;
$emptyString = '';
\Env::set('Resolver', $this);
\Env::set('Page', $this->page);
\Env::get('cx')->getComponent('Cache')->postFinalize($emptyString);
header('Location: ' . $target);
exit;
}
// in case the requested page is of type fallback, we will now handle/load this page
$this->handleFallbackContent($this->page, !$internal);
// set legacy <section> and <cmd> in case the requested page is an application
if ($this->page->getType() == \Cx\Core\ContentManager\Model\Entity\Page::TYPE_APPLICATION || $this->page->getType() == \Cx\Core\ContentManager\Model\Entity\Page::TYPE_FALLBACK) {
$this->command = $this->page->getCmd();
$this->section = $this->page->getModule();
}
}