本文整理汇总了PHP中JMenu::getActive方法的典型用法代码示例。如果您正苦于以下问题:PHP JMenu::getActive方法的具体用法?PHP JMenu::getActive怎么用?PHP JMenu::getActive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JMenu
的用法示例。
在下文中一共展示了JMenu::getActive方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct()
{
$this->app = \JApplicationCms::getInstance('site');
$lang = \JFactory::getLanguage();
$tag = \JLanguageMultilang::isEnabled() ? $lang->getTag() : '*';
$this->menu = $this->app->getMenu();
$this->default = $this->menu->getDefault($tag);
$this->active = $this->menu->getActive();
}
示例2: parse
/**
* Parse method for URLs
* This method is meant to transform the human readable URL back into
* query parameters. It is only executed when SEF mode is switched on.
*
* @param array &$segments The segments of the URL to parse.
*
* @return array The URL attributes to be used by the application.
*
* @since 3.3
*/
public function parse(&$segments)
{
/*
* Available urls:
*
* projects
* {project}
* {project}/issues
* {project}/{issue}
* {project}/{issue}/edit
* comment/edit/{comment}
* comments
*/
$query = array('option' => 'com_monitor');
if (empty($query['Itemid'])) {
$menuItem = $this->menu->getActive();
} else {
$menuItem = $this->menu->getItem($query['Itemid']);
}
if (empty(array_filter($segments))) {
return $menuItem->query;
}
$menuQuery = $menuItem !== null && $menuItem->query['option'] === self::COMPONENT ? $menuItem->query : null;
self::convertTaskToView($menuQuery);
$menuView = isset($menuQuery['view']) ? $menuQuery['view'] : null;
if ($segments[0] == 'projects') {
$query['view'] = 'projects';
} elseif ($segments[0] == 'issues') {
$query['view'] = 'issues';
if ($menuView == 'project' && isset($menuQuery['id'])) {
$query['project_id'] = $menuQuery['id'];
}
} elseif ($segments[0] == 'comment') {
$query['view'] = 'comment';
$query['layout'] = $segments[1] === 'delete' ? 'delete' : 'edit';
if (isset($segments[1]) && $segments[1] == 'new' && is_numeric($segments[2])) {
$query['issue_id'] = $segments[2];
} elseif (is_numeric($segments[2])) {
$query['id'] = $segments[2];
}
} elseif ($segments[0] == 'comments') {
$query['view'] = 'comments';
} elseif (is_numeric($segments[0])) {
$query['view'] = 'issue';
$query['id'] = $segments[0];
if (isset($segments[1]) && $segments[1] === 'edit') {
$query['layout'] = 'edit';
}
} elseif ($segments[0] === 'edit' || $segments[0] === 'new') {
$query['layout'] = 'edit';
if ($menuView === 'comment') {
$query['view'] = 'comment';
if (is_numeric($segments[1])) {
if ($segments[0] === 'new') {
$query['issue_id'] = $segments[1];
} else {
$query['id'] = $segments[1];
}
}
} else {
$query['view'] = 'issue';
if ($segments[0] === 'new') {
if (isset($menuQuery['id'])) {
$query['project_id'] = $menuQuery['id'];
} elseif (isset($menuQuery['project_id'])) {
$query['project_id'] = $menuQuery['project_id'];
}
} else {
if (isset($menuQuery['id'])) {
$query['id'] = $menuQuery['id'];
}
}
}
} else {
// {project}
if (!isset($segments[1])) {
$id = $this->modelProject->resolveAlias($segments[0]);
$query['view'] = 'project';
$query['id'] = $id;
} else {
// {project}/issues
if ($segments[1] === 'issues') {
$id = $this->modelProject->resolveAlias($segments[0]);
$query['view'] = 'issues';
$query['project_id'] = $id;
} else {
$query['view'] = 'issue';
// {project}/new
if ($segments[1] === 'new') {
//.........这里部分代码省略.........
示例3: parseSefRoute
//.........这里部分代码省略.........
if (empty($route)) {
// If route is empty AND option is set in the query, assume it's non-sef url, and parse apropriately
if (isset($vars['option']) || isset($vars['Itemid'])) {
return $this->parseRawRoute($uri);
}
$item = $this->menu->getDefault($this->app->getLanguage()->getTag());
// If user not allowed to see default menu item then avoid notices
if (is_object($item)) {
// Set the information in the request
$vars = $item->query;
// Get the itemid
$vars['Itemid'] = $item->id;
// Set the active menu item
$this->menu->setActive($vars['Itemid']);
$this->setVars($vars);
}
return $vars;
}
// Parse the application route
$segments = explode('/', $route);
if (count($segments) > 1 && $segments[0] == 'component') {
$vars['option'] = 'com_' . $segments[1];
$vars['Itemid'] = null;
$route = implode('/', array_slice($segments, 2));
} else {
// Get menu items.
$items = $this->menu->getMenu();
$found = false;
$route_lowercase = JString::strtolower($route);
$lang_tag = $this->app->getLanguage()->getTag();
// Iterate through all items and check route matches.
foreach ($items as $item) {
if ($item->route && JString::strpos($route_lowercase . '/', $item->route . '/') === 0 && $item->type != 'menulink') {
// Usual method for non-multilingual site.
if (!$this->app->getLanguageFilter()) {
// Exact route match. We can break iteration because exact item was found.
if ($item->route == $route_lowercase) {
$found = $item;
break;
}
// Partial route match. Item with highest level takes priority.
if (!$found || $found->level < $item->level) {
$found = $item;
}
} elseif ($item->language == '*' || $item->language == $lang_tag) {
// Exact route match.
if ($item->route == $route_lowercase) {
$found = $item;
// Break iteration only if language is matched.
if ($item->language == $lang_tag) {
break;
}
}
// Partial route match. Item with highest level or same language takes priority.
if (!$found || $found->level < $item->level || $item->language == $lang_tag) {
$found = $item;
}
}
}
}
if (!$found) {
$found = $this->menu->getDefault($lang_tag);
} else {
$route = substr($route, strlen($found->route));
if ($route) {
$route = substr($route, 1);
}
}
if ($found) {
$vars['Itemid'] = $found->id;
$vars['option'] = $found->component;
}
}
// Set the active menu item
if (isset($vars['Itemid'])) {
$this->menu->setActive($vars['Itemid']);
}
// Set the variables
$this->setVars($vars);
// Parse the component route
if (!empty($route) && isset($this->_vars['option'])) {
$segments = explode('/', $route);
if (empty($segments[0])) {
array_shift($segments);
}
// Handle component route
$component = preg_replace('/[^A-Z0-9_\\.-]/i', '', $this->_vars['option']);
if (count($segments)) {
$crouter = $this->getComponentRouter($component);
$vars = $crouter->parse($segments);
$this->setVars($vars);
}
} else {
// Set active menu item
if ($item = $this->menu->getActive()) {
$vars = $item->query;
}
}
return $vars;
}
示例4: twocolumnRedirect
function twocolumnRedirect()
{
$mainframe= JFactory :: getApplication();
$option= JRequest :: getVar('option');
$view= JRequest :: getVar('view');
$layout= JRequest :: getVar('layout');
$task= JRequest :: getVar('task');
if (empty($layout) && $option=="com_osemsc" && $view=="register" && ($task!="login" && $task!="logout"))
{
/*
$redirecturl= "index.php?option=com_osemsc&view=register&layout=twocolumns";
$db= & JFactory :: getDBO();
$query= "SELECT id FROM `#__menu` WHERE `link` LIKE '$redirecturl%'";
$db->setQuery($query);
$result= $db->loadResult();
$Itemid=(!empty($result)) ? "&Itemid=".$result : "";
*/
jimport( 'joomla.application.menu' );
$redirecturl = JMenu::getActive();
$redirect= JRoute :: _($redirecturl."&layout=twocolumns");
$redirect= str_replace("&", "&", $redirect);
$mainframe->redirect($redirect);
}
}