Wednesday, 15 February 2012

php - how to insert registration "datetime" and last login "datetime" in cakephp -



php - how to insert registration "datetime" and last login "datetime" in cakephp -

i have completed blog tutorial in cakephp documentation. easy , fun. i'm confused on 1 thing. while creating blog in cakephp had 2 fields, "created" , "modified", in "posts" table.

cakephp automatically did updates there. didn't write code it.

now after completing tutorial want create simple registration form , login page. question field names have utilize in database cakephp automatically update "registration date , time" , "last login" every user.

oh, , also, if have "password" field in table "users" cakephp automatically hash password before storing in database? , if hashing algorithm used? , if have separate "salt" field in table "users" take care of too, automatically?

created filled "automagicly" on record creation 1 time user submit registration form save info in users table user model model :

$this->user->save($this->request->data);

cakephp set created & modified moment, can utilize created registration date. on other hand modified updated each time modification has been done user record.

if want maintain login date & maybe ip address etc., update them in login function :

public function login() { if ($this->request->is('post')) { if ($this->auth->login()) { $this->updateloginfields(); } } } protected function updateloginfields(){ $this->user->id = $this->auth->user('id'); $this->user->read(); $this->user->data['user']['ip'] = $this->request->clientip(); $this->user->data['user']['logindate'] = date('y-m-d h:i:s'); $this->user->save($this->user->data, false); }

as authentication recommand read authentication & acl tutorials in documentation

php mysql cakephp

No comments:

Post a Comment