I try to create a service in Phalcon, that only increments a number.
My Class:
<?php
class FormCounter {
private $counter = 0;
public function increment() {
$this->counter++;
return $this->counter;
}
}
In services:
$di->set('formCounter', function () {
return FormCounter();
});
In my Form Class I want to create an ID in every form with increments. The first form i create will have ID "form_1", second "form_2" etc.
$this->form_id = $this->getDi()->getFormCounter()->increment();
But it won't increment. It returns 1 everytime. How do I do this without using global variables?