Resetting task value after executing

For Joomla! 2.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Note: All 1.6, 1.7 and 3.5 releases have reached end of life and should be updated to 3.x.

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
serggn
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri Oct 29, 2010 11:03 am

Resetting task value after executing

Post by serggn » Wed May 04, 2011 9:16 am

Hi, all.

I am creating component and have problem with custom export button.
It executes controller's method export:

Code: Select all

function export_excel()
{
  $app = &JFactory::getApplication();
  $model = $this->getModel('Hardware');
  $data = $model->getExportItems();
  HardwareExport::export($data);
  $app->close();
}
After export execution, the value of hidden input (controller.export) remains, and when for example I apply search filter by submiting search button then export performs again.

How I can reset this value?

Thanks.

User avatar
Bakual
Joomla! Guru
Joomla! Guru
Posts: 781
Joined: Sun Dec 13, 2009 9:00 pm
Location: Switzerland
Contact:

Re: Resetting task value after executing

Post by Bakual » Wed May 04, 2011 4:06 pm

Did you try

Code: Select all

JRequest::setVar('task', '');
?

serggn
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri Oct 29, 2010 11:03 am

Re: Resetting task value after executing

Post by serggn » Thu May 05, 2011 6:19 am

Yes I did. I tried this:

Code: Select all

public function export()
{
		// Resetting task
		JRequest::setVar('task', '');

		$app = &JFactory::getApplication();
		// get export data
		$model = $this->getModel('Hardware');
		$data = $model->getExportItems();
		// export
		HardwareExport::export($data);

		$app->close();
}
but hardware.export still as value of input.

User avatar
Bakual
Joomla! Guru
Joomla! Guru
Posts: 781
Joined: Sun Dec 13, 2009 9:00 pm
Location: Switzerland
Contact:

Re: Resetting task value after executing

Post by Bakual » Thu May 05, 2011 8:58 am

No clue then. But I don't use $app->close() at the end of my functions, maybe this does something strange?

User avatar
linpi
Joomla! Apprentice
Joomla! Apprentice
Posts: 45
Joined: Sat Sep 23, 2006 6:35 am
Location: Berlin
Contact:

Re: Resetting task value after executing

Post by linpi » Mon Nov 04, 2013 10:12 pm

did some one find the solution to this problem ? I want to export a csv file as well, and after the export, my component sticks with the export task for ever.... no way the reset the task

User avatar
Bakual
Joomla! Guru
Joomla! Guru
Posts: 781
Joined: Sun Dec 13, 2009 9:00 pm
Location: Switzerland
Contact:

Re: Resetting task value after executing

Post by Bakual » Tue Nov 05, 2013 6:53 am

How are you setting the task to begin with? If you set the task using JavaScript to fill a (hidden) task input field, then it will obviously stay there till you reload the page. Maybe even longer if the content of the form is cached in the session somehow.
If you just add the task into the request URL, then there is no way it could stay.

User avatar
linpi
Joomla! Apprentice
Joomla! Apprentice
Posts: 45
Joined: Sat Sep 23, 2006 6:35 am
Location: Berlin
Contact:

Re: Resetting task value after executing

Post by linpi » Tue Nov 05, 2013 10:23 am

the task (csv) a custom toolbar

in the default view exportcsv/view.html.php, I check if the export toobar as been clicked.

Code: Select all

$is_export = JFactory::getApplication()->input->get('task', '');
        if ($is_export == 'csv') {
            ExporterViewExportcsv::export_csv($items);
        }
The problem didn't happen when I tried just with an
echo '*** I am in Export-CSV ***'; in export_csv.
That why I thought the logic was OK.

The task problem happens when I put the file export code, which begins with @ob_end_clean(); some headers (e.g. header("Content-Type: application/octet-stream");) and ends with an exit();

The export works though.

Maybe I have to change the logic.... and really make a view just for the export and not make an if-condition in the default view.

User avatar
Bakual
Joomla! Guru
Joomla! Guru
Posts: 781
Joined: Sun Dec 13, 2009 9:00 pm
Location: Switzerland
Contact:

Re: Resetting task value after executing

Post by Bakual » Tue Nov 05, 2013 11:12 am

if you are referring to the regular Joomla toolbar, then in fact you are using the JavaScript/hidden input field solution I mentioned.
That means when the button is pressed, the JavaScript first inserts the value into the task field and then submits the form. If the page is not refreshed, this input will stay filled with your task value, which is probably what you see.

Usually, we refresh the page after the task is processed by sending a redirect to the browser. But if you close the application manually ($app->close, exit() or similar), this is likely not done.

So the solution to your problem is to send a redirect to the browser so the page gets reloaded. You can use http://api.joomla.org/Joomla-Platform/A ... l#redirect to do that.

SPQRInc
Joomla! Intern
Joomla! Intern
Posts: 60
Joined: Sun Jan 05, 2014 1:00 pm

Re: Resetting task value after executing

Post by SPQRInc » Fri Feb 19, 2016 3:44 pm

Hello,

I'm facing the same problem and I do not know how to solve it.

I try to export a csv using JTooblar-Buttons - if I export something the file is being downloaded. If I change the state in the filter-bar after download succeeded, the download starts again.


Could you explain how to set the redirect correctly in my controller?


Locked

Return to “Joomla! 2.5 Coding”