【问题标题】:SEF in Joomla 3.0Joomla 3.0 中的 SEF
【发布时间】:2013-05-10 20:41:00
【问题描述】:

我正在使用 joomla 3.0 并在其中创建了一个组件。现在 SEF 网址有一个问题。

在我的组件中,我实现了 MVC 结构。我的视图结构,例如 View/Name of View/tmpl/default.php

我的非 SEF 网址是:index.php?option=component Name&view=name of view&layout=default

当我尝试使用 router.php 文件创建 SEF url 时,它将创建 URL index.php/component/组件名/视图名/default?layout=default

但我想要像 index.php/component/name of component/name of view/default

这样的 url

我的 router.php 文件是:

function componentNameBuildRoute( &$query )
 {
      if(isset($query['view']))
       {
             $segments[] = $query['view'];
             unset( $query['view'] );
       }
      if(isset($query['layout']))
       {
              $segments[] = $query['layout'];
       };
 }
 function ComponentNameParseRoute($segments)
 {
       $vars = array();
       $app =& JFactory::getApplication();
       $menu =& $app->getMenu();
       $item =& $menu->getActive();
       // Count segments
       $count = count( $segments );
       if( $segments[0] == 'Profile')
       {
       $vars['view'] = 'Profile';
       $vars['layout'] = 'default';
    }
 }

当我取消设置布局段时,它会给出如下网址:

index.php/组件/组件名/视图名/默认

但它没有显示我的页面

在 joomla 2.5 中它可以正常工作,但在 joomla 3.0 中它不工作

【问题讨论】:

  • '它不工作' -- error.log?

标签: php joomla joomla3.0


【解决方案1】:

您需要取消设置布局查询:

unset( $query['layout'] );

取消布局会阻止 URL 包含 ?layout=default 部分。

还要确保在 ComponentnameBuildRoute 函数的末尾使用 return $segments;

如果此 URL 未显示页面,则表示 ComponentnameParseRoute 函数失败。 这对我来说有点难说,因为我不知道您的视图名称,但是您需要检查 $segments[0] 的每个可能值(视图名称)并相应地设置变量。另外我建议使用小写的视图名称。

当然也可以在函数末尾使用return $vars; 来返回变量。

我在我的扩展中使用了这样的东西:

function ComponentnameParseRoute($segments)
{
    $vars = array();
    // Check View
    switch ($segments[0])
    {
        case 'profile':
        default:
            $vars['view'] = 'profile';
            break;
        case 'anotherview':
            $vars['view'] = 'anotherview';
            break;    
    }
    // Check Layout
    if ($segments[1])
    {
        $vars['layout'] = $segments[1];
    }
    return $vars;
}

【讨论】:

  • 如果我取消布局,页面将不会显示
猜你喜欢
  • 2012-12-10
  • 1970-01-01
  • 1970-01-01
  • 2012-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多