我有一个表单,在提交时我将值传递给控制器,数组看起来像这样。
[submit] => Post
[File] => Array
(
[content] => dfgdfgdfg
)
[Groups] => Array
(
[group_name] => 190
)
[News] => Array
(
[is_private] => 1
[user_id] => 285
[content] => <p>dfgdfgdfg</p>
)
[Posts] => Array
(
[rating] => 5.2
[rating_enabled] => on
)
除评级之外的所有值都正确保存到数据库中。我在前端使用滑块,其值是评级。 在db中,rating字段是十进制类型,Posts [rating]的类型是string,所以我使用floatval将它转换为float。
if( isset($this->request->data['Posts']['rating_enabled']) ){
$this->request->data['News']['rating'] = floatval($this->request->data['Posts']['rating']);
}
完成保存后
$this->News->save($this->request->data);
仅保存$ this-&gt; request-&gt;数据[&#39;新闻&#39;] [&#39;评级&#39;]未保存,但在检查数据数组时,其值为
[News] => Array
(
[is_private] => 1
[user_id] => 285
[content] => <p>dfgdfgdfg</p>
[rating] => 5.2
)
有人能告诉我错误吗
答案 0 :(得分:0)
请检查mysql表评级必须是float