setting joomla component router.php

2019-06-14 07:04发布

问题:

I am using joomla 1.5 and building a simple component for sfowing the states and cities of USA. The problem has arrised in my router.php file. My router.php is as follows

function DesignBuildRoute(&$query)
{
  $segments = array();

  if(isset($query['task'])) 
  {
    $segments[] = $query['task'];       
    unset($query['task']);
  };

  if(isset($query['state']))
  {
    $segments[] = $query['state'];
    unset($query['state']);
  };

  return $segments;
}

function DesignParseRoute($segments)
{
  $vars = array();
  $vars['task'] = $segments[0];
  $vars['state']        = $segments[1];
  return $vars;
}

the problem is this, that i have got the required url, [menualias]/[state].html, but when I go to the page, object not found page is displayed. Can anyone help me. what is wrong with my router.php

回答1:

Please check Item id in url and i am sending my code .follow my code and create you router file .

function demoBuildRoute(&$query) {

   $segments = array();

if (isset($query['view'])) {
   $segments[] = $query['view'];
    unset($query['view']);
}

if (isset($query['link_id'])) {
   $segments[] = $query['link_id'];
    unset($query['link_id']);
}

if (isset($query['Itemid'])) {
   $segments[] = $query['Itemid'];
    unset($query['Itemid']);
}

return $segments;

}


function demoParseRoute($segments) {

    $vars = array();
    $count = count($segments);   
   if ($count == '1') 
   {

      $vars['view']   = $segments[0];
      $vars['Itemid'] = $segments[1];
   }

   if ($count == '2') 
   {
      $vars['view']   = $segments[0];
      $vars['Itemid'] = $segments[1];
   }

   if ($count == '3') 
   {
      $vars['view']    = $segments[0];
      $vars['Itemid']  = $segments[2];
   }

     return $vars;

} 

Check ur url and create router file.



标签: php joomla