Page 1 of 1

clear cache and redirect after_new_action

PostPosted: Mon Oct 24, 2011 12:16 pm
by manifold
Hello all,

Typically, upon adding/editing/deleting a record, a confirmation screen is presented, and (apparently) the cache is cleared and the new state of the record is visible (eg, the new value for an edited field has replaced the original value).

I now have a custom action which updates one table after a modification in another, by way of a custom query (thanks to ADobkin). Here's the problem: the record is modified; the record is saved; upon saving, the associated table is modified; BUT the screen simply turns white, not returning a 'record modified' message (or anything, for that matter, not even the execution time). I must manually clear the cache, and .. voila... the record modification is now visible. But this is cumbersome, and frankly inscrutable to the folks I am trying to encourage to use my system.

I've researched the forums here, and I've tried several of the variations of the options potentially available; none has worked. Perhaps I have missed something.

So: If anyone has any insights or suggestions, I'd appreciate them!

TIA,
-manifold

Re: clear cache and redirect after_new_action

PostPosted: Mon Oct 24, 2011 1:45 pm
by shannah
If the screen is turning white it looks like you have a fatal error. Check your error logs.

Re: clear cache and redirect after_new_action

PostPosted: Mon Oct 24, 2011 2:16 pm
by manifold
The error log is clear... at least, no error is recorded.

If I manually reload the page with a ' ?-action=clear_cache', and then go back to the table that should have been modified.. .I see that it in fact *has* been modified.

So, the custom query:

Code: Select all
function afterSave(&$record){
      $this->app =& Dataface_Application::getInstance();
   $vin = $record->val('vin'); // refers to value of workorder.vin
      $inservice = $record->val('inservice'); // refers to value of workorder.inservice
      $result = mysql_query("UPDATE apparatus SET status='$inservice' where vin='$vin'", $this->app->db());
}


returns a white screen, even though the table & record had been properly changed. But I have to manually do a
reload of the page with a '-action=clear_cache' suffix.

The custom query does seem to work; I'm just trying to get it to return a standard 'record successfully modified' page...

Re: clear cache and redirect after_new_action

PostPosted: Mon Oct 24, 2011 2:25 pm
by shannah
Does it work if you disable the output cache, or do you get the same thing?

Re: clear cache and redirect after_new_action

PostPosted: Mon Oct 24, 2011 3:51 pm
by manifold
Same thing!

Re: clear cache and redirect after_new_action

PostPosted: Mon Oct 24, 2011 5:02 pm
by shannah
Sounds like the output cache is a red herring then. It is more likely that there is an error happening some time during the save. Strange that it's not in your error log. Try putting strategic die('here') statements at various places in your afterSave() method to see where it is dying.

Perhaps there is another error log somewhere that it is writing to?

Update:Re: clear cache and redirect after_new_action

PostPosted: Wed Oct 26, 2011 6:09 am
by manifold
I had recently included a 'getTitle' function in my apparatus.php class delegate file:

Code: Select all
<?php

class tables_apparatus {

   function getTitle(&$record) {
      return $record->display('recno') . ' - ' . $record->display('designation');
   }
}
?>


By using this file, a white screen is returned upon updating a workorder record (this updates the availability status of a vehicle; the custom query that updates an apparatus record upon saving the workorder is identified above). If I remove the getTitle function... the workorder returns properly with a 'record successfully saved' message, and the apparatus table is successfully updated.

Though for the life of me, I can't understand why!

Re: clear cache and redirect after_new_action

PostPosted: Wed Oct 26, 2011 6:45 am
by ADobkin
Maybe there is something in one of those fields that isn't working with the getTitle function. Instead of using the $record->display() functions, try using $record->val() or $record->strval().

Re: clear cache and redirect after_new_action

PostPosted: Wed Oct 26, 2011 6:48 am
by FractalizeR
You can clear cache from your action by using

Code: Select all
<?php
Dataface_SkinTool::getInstance()->clear_all_cache();