I am having problems with a test implementation of a checkout, using the Dutch psp Mollie. The problem is not Mollie related. What is happening is that the index function below is sometimes called twice, resulting in two records in my sales table. I am a little at a loss why this is happening. Below I pasted my test code that results in the strange behaviour. I already tried to change the route, but to no avail. The same is happening, even if I move the code to the route /test/send
, or when I link the /test
stub to another function, like '' => 'send'
.
The dataobject "Sale" has no extra code apart from the default $db and $has_something etc.
Update: I removed all the Mollie related code, and the application is still doing the same thing. I think the redirect has something to do with it, because when I remove it the problem does not surface (it only occurs the first reload after I remove it, after that, a reload just results in one row in the database). When the reload is in place it happens a whole lot more often (but I still can't really predict when or why).
Update2: I tried a fresh install, and still the same problem. As the site is hosted on a LEMP stack, I also tried a fresh install on a LAMP stack. Still the same problem...
Update3: I made a minimal example of code that still shows the same behavior, and updated the code below accordingly
class TestController extends Controller {
public function index() {
$sale = Sale::create();
$sale->TicketName = "test ".date("Y-m-d H:i:s");
$sale->write();
return $this->redirect("http://other.site");
}
}
The Sale dataobject
class Sale extends DataObject {
private static $db = array(
"TicketName" => "Varchar(255)",
);
}
class SaleAdmin extends ModelAdmin {
private static $managed_models = array('Sale');
private static $url_segment = 'Sales';
private static $menu_title = 'Sales';
}
And this is the route.yml
---
Name: myroutes
After: framework/routes#coreroutes
---
Director:
rules:
'test' : 'TestController'
TestController
fromPage_Controller
. Have you tried to inherit fromController
instead, as suggested in my answer?.htaccess
for any oddities?