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/