I am currently making a time-clock system that is inside of a custom-built application (CRM) that a previous developer did. I’ve got the timeclock coming along nicely but have just a few questions..
Upon clocking in I set a session like so: $this->get('session')->set('clockedin', 'true');
I set a session so that I in order to show the clockin or clockout button I figured the easiest method would be to just read a session variable to determine which button to show using a twig if/else statement in the templates (i have the buttons show in 2 places, 1 is in every page and 1 is only in the timeclock system itself)
So, is this the best way to go about doing this or is there a better recommended way of going about it?
The next thing I wondered about is session expiration… in my config.yml I see:
session:
cookie_lifetime: 43200
auto_start: true
So, does this mean that the way i’ve set it lasts for 12 hours? Or in order for that to be true, would I need to use a cookie instead? I think that a cookie might be better, because if the browser closes (many of the employees aren’t technologically inclined) I’d need this to be a persistent upon the next page load..
Thanks for any help..
If another indefinitely later operation depends on
clockedinstate I would not rely on sessions. If user logs him/herself out session gets invalidated (whole session), soclockedinwould be lost.I would rather use
{% include %}or{% render %}to determine state every time you need to display that button. For example:and in your Twig:
Template of this controller would contains that
{% if .... %}you wanted originally:Now, this is more expensive since on each request you have to assess the situation and then print appropriate template, but it’s always consistent with a system…