php - save data in cakephp database -


i have cakephp web app i'm developing. have userscontroller.php file,which handles users registrations , logins. when user logged in,he can use functionality of featurescontroller.php. fueaturescontroller.php has view file,the create.ctp . in create.ctp,the user inserts data html form , these data saved database,using $this->modelname->save($this->request->data).

now,i want add field of database username of user did/used html,but till have not succeed! code looks this:

$username = $this->session->read('auth.user.username'); 

so save username of user variable $username.

but now,how can insert database? have tried various ways didn't work :/

anyone's welcomed,thank in advance :)

you shouldn't add username form, it's not secure malicious user has modify html change it. instead, should set right before saving:

$this->request->data['modelname']['username'] = $this->auth->user('username'); $this->modelname->save($this->request->data); 

assuming you're using authentication component $this->auth->user('username'); same $this->session->read('auth.user.username'); way, bit shorter.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -