0
votes

I am using joomla 3.0 and created one component in it. Now one Problem with SEF url.

In my component i have implement MVC structure. my view structure like View/Name of View/tmpl/default.php

My Non-SEF url is :index.php?option=component Name&view=name of view&layout=default

When i am trying to make SEF url using router.php file, then it will create URL index.php/component/name of component/name of view/default?layout=default

but i want url like index.php/component/name of component/name of view/default

my router.php file is :

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';
    }
 }

When i unset layout segment then it give url like:

index.php/component/name of component/name of view/default

but it is not displaying my page

in joomla 2.5 it work properly,but in joomla 3.0 it is not working

1
'it is not working' -- error.log? - sectus

1 Answers

1
votes

You need to unset the layout query:

unset( $query['layout'] );

Unsetting the layout prevents the URL from having the ?layout=default part in it.

Also make sure to use return $segments; the end of your ComponentnameBuildRoute function.

If this URL doesn't show the page, it means the ComponentnameParseRoute function fails. This is a bit hard to tell for me since I don't know the names of your views, but you need to check $segments[0] for every possible value (viewname) and set the vars accordingly. Also I would recommend to use lowercase viewnames.

And of course also return the vars here using return $vars; at the end of the function.

I use something like this in my extension:

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;
}