简体   繁体   English

如何使用cakephp中的复选框将数据保存在数据库中

[英]how to save data on database using checkbox in cakephp

I am new in cakephp so I want to store value 1 in db when user checked the check box also stay checked after update please help me to resolve this issue. 我是Cakephp的新手,所以当用户选中复选框时,我想在数据库中存储值1,更新后该复选框也保持选中状态,请帮助我解决此问题。

One more thing default value to Userhistory.tillnow is 0 Userhistory.tillnow件事默认值为0

 <?php echo $this->Form->create('Userhistory', array('class' => 'form-inline')); ?>
 <?php echo $this->Form->input('Userhistory.tillnow', array('type' => 'checkbox')); ?>` 
 <?php echo $this->Form->end(); ?>`

Follow these steps 跟着这些步骤

  1. Change the Database column to a TINYINT(1) for Boolean columns. 将Boolean列的Database列更改为TINYINT(1)。
  2. Save your request data 保存您的请求数据

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM