user3033136
user3033136

Reputation: 129

Joomla setredirect override in save method breaks apply method

I have three toolbar buttons in my edit page of my component (joomla 3.0).

view.html.php

protected function addToolBar()
{
  JToolBarHelper::apply('editpage.apply');
  JToolBarHelper::save('editpage.save');
  JToolBarHelper::cancel('editpage.cancel');
}

This works great. But now when I change the redirect path of my save method in the controller like this...

controller/editpage.php

function save()
{
  parent::save();
  $this->setredirect(JRoute::_('index.php?option=com_mycom&view=productlist', false));
}

... than by a click on "apply", the user was also redirected to this path. And this is the problem. Without this override method in controller, the apply button works fine. All fields will be saved and the edit page will not leave. So how can I solve that problem?

Upvotes: 1

Views: 1806

Answers (1)

Both Save and apply method call to the same function of joomla library to save the records. The better way to over come the issue is

view.html.php

protected function addToolBar()
{
  JToolBarHelper::apply('editpage.tasktoApply');   // any name other then apply
  JToolBarHelper::save('editpage.tasktoSave');  // any name other then save
  JToolBarHelper::cancel('editpage.cancel');
}

controller/editpage.php

function tasktoApply()
{
  parent::save();
  $this->setredirect('ANY CUSTOM REDIRECT AS PER YOUR NEED', false));
}

function tasktoSave()
{
  parent::save();
  $this->setredirect('ANY CUSTOM REDIRECT AS PER YOUR NEED', false));
}

This would sort out your issue

Upvotes: 1

Related Questions