PHP MVC表单提交

I have a question related to form submission done in PHP application that's built in MVC architecture (self-written framework).

All examples that I've seen so far (including existing back-end frameworks) work this way that once form for adding record to database is submitted then certain method of controller is executed [say i.e. addRecord()], which triggers method of appropriate model. If everything goes OK then record is added and controller's method [addRecord() in this example] renders view of "index" page that displays table with records from database.

What I would like to achieve is to render view with form used to add records (the same that I used to add first record) instead of "index". Obviously I can do it easily by just rendering appropriate view from addRecord() (view with the form).

But the tricky point is when you check url you'll see the following: The first time you enter it will be i.e.

http://project_name/my_controller/create

Once first form was submietted and you return to the view from addRecord() method then url will be:

http://project_name/my_controller/addRecord

What I would like to see is return to the original url, that is http://project_name/my_controller/create

Not sure if this is clear?

PS. Of course I could use AJAX call for form submission (that way I will stay at the same page) but perhaps it's possible to achieve the same without AJAX.

Thanks in advance,

On the controller you will want to submit to the addRecord route and do the processing. Have a check to make sure it was successful and on successful submission you can redirect back to the create route.

It is hard to give an example since you are using a custom made framework. I use slim which has a redirect method for a route. If what you have made does not have something like that then using should do the trick.

header('Location: '.$createUrl);
die(); //or exit