如何跟踪我在Ca​​kePHP中提交表单的次数?

时间:2022-10-20 15:48:24

I need some idea in Saving the Form entries.

我在保存表单条目时需要一些想法。

In my app, I have designed the form using Cakephp and JQuery, saved the form and I can view the form.

在我的应用程序中,我使用Cakephp和JQuery设计了表单,保存了表单,我可以查看表单。

While I fill the entries in the form it is saved in my results table. My results table schema looks like this: (id, form_id, attribute_id, label, value)

当我填写表单中的条目时,它会保存在我的结果表中。我的结果表模式如下所示:(id,form_id,attribute_id,label,value)

I can view the form n times and can fill the data n times ... But I didn't kept anything regarding Entry Number ...

我可以查看表格n次并且可以填写数据n次......但是我没有保留关于条目号的任何内容......

Like if I submitted my form once it should be the Entry 1 ..And later on if I open the form again and fill it it should be the entry 2. How can I accomplish this?

就像我提交我的表格一样,它应该是条目1 ..如果我再次打开表格并填写它,它应该是条目2.我怎样才能完成这个?

1 个解决方案

#1


If you want to count the numer of times you've revised each row in your table, then simply create a column named revision_number in your table with a default of 0. Then in your model do something like this:

如果你想计算你修改表中每一行的次数,那么只需在表中创建一个名为revision_number的列,默认值为0.然后在模型中执行以下操作:

function beforeSave() {
  $currentRevision = $this->field('revision_number');
  $this->data[$this->alias]['revision_number'] = ($currentRevision + 1);
  return parent::beforeSave()
}

This will increment your field every time you save the item.

每次保存项目时,这将增加您的字段。

#1


If you want to count the numer of times you've revised each row in your table, then simply create a column named revision_number in your table with a default of 0. Then in your model do something like this:

如果你想计算你修改表中每一行的次数,那么只需在表中创建一个名为revision_number的列,默认值为0.然后在模型中执行以下操作:

function beforeSave() {
  $currentRevision = $this->field('revision_number');
  $this->data[$this->alias]['revision_number'] = ($currentRevision + 1);
  return parent::beforeSave()
}

This will increment your field every time you save the item.

每次保存项目时,这将增加您的字段。