0

I am developing a component a component. When i click on a item or enter the URL like this "index.php?view=customercenter&id=31" i receive the id of the item with this code:

Controller:

public function display($cachable = false, $urlparams = false)
{
    $document       = JFactory::getDocument()->input;        
    $id = $this->input->get('id', 0, 'INT');
    $vName = $this->input->get('view', 'customercenter');
    $this->input->set('view', $vName);

    parent::display($cachable, $urlparams);

    return $this;

}

That works and i recieve the id "31". But when i enable sef-friendly urls and create the router.php, i always get "0"

Router.php:

function CustomerCenterBuildRoute( &$query ) {
$segments = array();
   if (isset($query['view']))
   {
            $segments[] = $query['view'];
            unset($query['view']);
   }
   if (isset($query['id']))
   {
            $segments[] = $query['id'];
            unset($query['id']);
   };
   return $segments; }
function CustomerCenterParseRoute($segments) {
   $vars = array();
   switch($segments[0])
   {
           case 'categories':
                   $vars['view'] = 'categories';
                   break;
           case 'category':
                   $vars['view'] = 'category';
                   $id = explode(':', $segments[1]);
                   $vars['id'] = (int) $id[0];
                   break;
           case 'article':
                   $vars['view'] = 'article';
                   $id = explode(':', $segments[1]);
                   $vars['id'] = (int) $id[0];
                   break;
   }
   return $vars;
}

The link:

<a href='" . JRoute::_('index.php?view=customercenter&id=' . $row->id . ':' . JFilterOutput::stringURLSafe($row->name) ) . "'>" . $row->name . "</a>

Does the method "input->get('id', 0, 'INT');" not work with sef-friendly urls?

1 Answer 1

1

Ok, i found the mistake, i had to replace "article" with the right name of the view in my component "customercenter":

Wrong:

case 'article':
                   $vars['view'] = 'article';
                   $id = explode(':', $segments[1]);
                   $vars['id'] = (int) $id[0];
                   break;

Correct:

 case 'customercenter':
                   $vars['view'] = 'customercenter';
                   $id = explode(':', $segments[1]);
                   $vars['id'] = (int) $id[0];
                   break;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.