php - How can i simplify the new sessions i create for a model which is linked? -
i have login action in control. sessions created auth.user, not auth.town. need create sessions. have several fields in towns table, , not want create 50 lines. how can make easier ? need simplify .
userscontroller :
public function login() { if ($this->request->is('post')) { if (isset($this->request->data['userlogin'])) { $this->request->data['user'] = $this->request->data['userlogin']; } if ($this->auth->login()) { $this->session->write( 'auth.town.name', $this->user->town->field('name') ); $this->session->write( 'auth.town.country', $this->user->town->field('country') ); $this->session->write( 'auth.town.localisation', $this->user->town->field('localisation') ); $this->session->write( 'auth.town.statut', $this->user->town->field('statut') ); return $this->redirect($this->auth->redirect()); }else{ $this->session->setflash("l'adresse électronique ou votre mot de passe ne correspond pas","notif",array('type'=>'error')); } } }
well, columns, loop , assignment:
$towns = array('name', 'country', 'localisation', 'statut'); foreach($towns $column) { $this->session->write( 'auth.town.' . $column, $this->user->town->field($column) ); }
Comments
Post a Comment