Quick search:

redirect after buttonexecution

lucb
2005-02-06 11:45:53
 
Hello,

All the examples and my own code too running on my own server show the same behaviour, when one clicks on an update, create or delete button after editing a record in the database the proper action is done on the entered data but afterwards the browser seems to load the root index.html page of the phppeanuts installation instead of coming back to the listview of the edited form.

The examples on the phppeanuts.org server behave different because altering the database is not allowed and you get an errormessage and stay on the same page.

Is this behaviour standard for the phppeanuts framework? Is it ment this way?
Is there an easy solution?

Groeten Luc
henk
2005-02-06 13:06:11
 
Hi Luc,

I recently had this problem myself. It happened when i installed an application in its production environment. I found it to be caused by a carriage return at the end of baseurl.txt. The solution, of course, is to make sure the baseurl.txt only contains the exact url, including the last slash, to your peanuts base folder, and no carriage returs or line feeds.

I was already asking myself how to make the baseurl less error-phrone. The txt file was introduced for the use of phpPeanuts with our CMS to serve the homepage of a website. I guess we better eliminate the baseurl.txt file from the version 1.1 of the framework and replace it with a setting in scriptMakeSettings.php:

$this->baseUrl = "http://yourserver/yourPeanutsPath/";

This way one will not occasionally put a carraige return in the baseUrl.

It works with older versions of the framework too and will override the content of baseurl.txt, though there may be some problems with reporting errors (redirect to error page) if the error handler is activated and an error occurs before scriptMakeSettings.php is included.

Sorry for the inconvenience,

Henk Verhoeven.


BTW:  If one needs phpPeanuts for a homepage, one can still reintroduce the baseurl.txt file by putting this into scriptMakeSettings.php:

$this->baseUrl = implode(file("../classes/baseurl.txt"),"");
lucb
2005-02-08 22:12:49
 
Thank you for the answer. I checked the baseurl.txt file but there was no cr behand the http statement. Then I changed the scriptMakeSettings.php like you said and that was the solution.

Now the upgrade button stays at the same page, better but better would be if it would go to the parent listview. Is this possible?

Groeten Luc
henk
2005-02-09 01:03:25
 
Hi Luc,

I suppose you mean the Update button. I have good news and bad news. The good news is that, like many aspects of the default phpPeanuts behavior, it can be overridden without changing the framework base code. The bad news is you have to program the override yourself. (Basically most of programming a phpPeanuts application is a matter of programming overrides, so if you like programming you may consider this good new too ;-) ).

The POST requests from both the update button and the new button are processed by an ObjectSaveAction. Initially it inherits all its behavior from pnt.web.actions.PntObjectSaveAction. What happens after saving the object is decided by the method finishSuccess.

You can override what happens by adding your own method finishSuccess to ObjectSaveAction. To see how to make it redirect to the context listpage, compare pnt.web.actions.PntObjectSaveAction::finishSuccess with pnt.web.actions.PntObjectDeleteAction::handeRequest. In PntObjectDeleteAction::handleRequest the line
$obj->delete();
actually deletes the object.
After that you can see that it, like PntObjectSaveAction::finishSuccess,  builds an array $newReq that is used by $this->redirect($newReq). What goes into $newReq depends on the request parameter 'pntContext'.

Try what happens if you copy everything below $obj->delete();
up to and including
return $this->redirectRequest($newReq, $this->getOKMessage($obj));
to your overriding finishSuccess method. With a little debugging you will probably get the redirect you are looking for.

This redirect should work with lists from an IndexPage and a PropertyPage. What this redirect can not do is redirect to the proper search result and the proper page-index if there are page buttons below the list. This will be solved in 1.2 beta by a more advanced context history. 1.2 beta is not yet available for download. The context history mechanism is currently being tested in pre-Alpha development versions at MetaClass. First 1.1 must be released (expected next friday or sunday). 1.2 beta may be available in March or April, but we can not make any promises on future releases (unless someone pays for them).

Greetings, Succes,

Henk Verhoeven,
MetaClass.

BTW, you are expected to add your own methods to the classes in the root classes folder, but not to change any code in the classes/pnt folder. If you install a phpPeanuts upgrade you will be expected to replace the classes/pnt folder entirely. For upgrading anything outside the classes/pnt folder we will supply detailed upgrade instructions*. If you have made changes to the code in the classes/pnt folder you are on your own.

* but for .js scripts only for specific.js



Post Edited (02-09-05 01:04)
henk
2005-02-09 01:06:12
 
Sorry, i reacted to the wrong message, see my other reaction
Add a Reply
Loading form, please wait
The website will not send you an e-mail when a reply is added to this topic

Back to Topics List