0

I've made joomla 2.5 (works in joomla 3 too) component.

To test component I've created a menu item "mycomtest-main" and placed component in that menu item page. So full local testing url is "localhost/joomla/mycomtest-main".

Component lists many items and there is a button when clicked entry form is shown which is a entry form view of my that mvc component and url becomes "localhost/joomla/mycomtest-main?task=edit&id=4", as I used JRoute::_("index.php?...") to keep safe url.

So after above entry form filled and submitted, it is redirected back to default view - localhost/joomla/mycomtest-main but unfortunately url becomes - localhost/joomla/component/mycomtest-main/ instead localhost/joomla/mycomtest-main.

My component entry form view look like below -

<form action="index.php" method="post" name="adminForm" id="adminForm" enctype="multipart/form-data">
    <input type="hidden" name="option" id="option" value="<?php echo $_REQUEST['option']; ?>" />
    <input type="hidden" name="task" id="task" value="save" />
    <input type="hidden" name="id" id="id" value="<?php if($row!=NULL){ echo $row->id; }?>" />
    <input type="hidden" name="page" id="page" value="<?php echo JRequest::getVar('page'); ?>" />
.............rest of the html contents along with submit button
</form>

Also in my mvc component's controller.php file I used jroute well this way -

function save()
    {   
        $model = $this->getModel('entry');
        if($model->store())
        {   $msg = "saved successfully"; $type = 'message'; }
        else
        { $msg = 'error found'; $type = 'error';
        }
        $urlSet=JRoute::_("index.php?option=". $_REQUEST['option']."");
        $this->setRedirect($urlSet, $msg, $type);
}

So how I go so that after entry view form submitted I am redirected to menu item page with correct url below? -

http://localhost/joomla/mycomtest-main/
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
developer
  • 78
  • 1
  • 13

1 Answers1

0

That is because you did not build the router for the component. you can check the router.php located inside components/com_user or write your own routing follow this one http://docs.joomla.org/Routing

or you can do like this every time you using redirect:

$menu = $app->getMenu();
      $items  = $menu->getItems('component', 'com_yourcom');
      $itemid = JRequest::getint( 'Itemid' );
      for ($i = 0, $n = count($items); $i < $n; $i++) {
      // Check to see if we have found the resend menu item.
        if (!empty($items[$i]->query['view']) && ($items[$i]->query['view'] == 'yourview')) {
          $yourviewid = $items[$i]->id;
        }
      }
$redirect = JRoute::_("index.php?option=com_yourcom&Itemid=".$yourviewid ,false);
      $this -> setRedirect($redirect);
Duc Phan
  • 175
  • 1
  • 3
  • 14