cakephp 新字段不保存

标签 cakephp

如何扩展 cakePHP 项目以便它可以使用数据库中的新字段?

我刚刚给出了一个 CakePHP 项目,我试图扩展该模型以包含一个新字段。我原来的 Developer 不再可用,而且我以前没有使用过 CakePHP。问题是所有其他字段都被正确保存,但新字段被保存为空字符串。

数据库已扩展为包括新字段:

class_time  varchar(30)

我扩展了原来的 View 来支持新的领域
<?=$form->input('release', array('type' => 'radio', 'legend' => false, 'div' => 'radio', 'options' => array('Agree' => 'Agree &nbsp;', 'Disagree' => 'Disagree')))?>
<?=$form->input('class_time', array('type' => 'radio', 'legend' => false, 'div' => 'radio', 'options' => array('No preference' => 'No preference&nbsp;', '6:00-8:30 P.M. ' => '6:00-8:30 P.M. ', '6:30-9:00 P.M.' => '6:30-9:00 P.M.')))?>

据我所知,该页面正在正确呈现 HTML
<div class="radio"><input type="hidden" name="data[Account][release]" id="AccountRelease_" value=""><input type="radio" name="data[Account][release]" id="AccountReleaseAgree" value="Agree"><label for="AccountReleaseAgree">Agree &nbsp;</label><input type="radio" name="data[Account][release]" id="AccountReleaseDisagree" value="Disagree"><label for="AccountReleaseDisagree">Disagree</label></div>
<div class="radio"><input type="hidden" name="data[Account][class_time]" id="AccountClassTime_" value=""><input type="radio" name="data[Account][class_time]" id="AccountClassTimeNoPreference" value="No preference"><label for="AccountClassTimeNoPreference">No preference&nbsp;</label><input type="radio" name="data[Account][class_time]" id="AccountClassTime6:00-8:30P.m." value="6:00-8:30 P.M. "><label for="AccountClassTime6:00-8:30P.m.">6:00-8:30 P.M. </label><input type="radio" name="data[Account][class_time]" id="AccountClassTime6:30-9:00P.m." value="6:30-9:00 P.M."><label for="AccountClassTime6:30-9:00P.m.">6:30-9:00 P.M.</label></div>

但是当它保存时,它会保存“发布”字段(和其他字段)的选择,而不是 class_time。

从我在 cakePHP 文档中可以找到的内容来看,app/models/account.php 是我认为我需要定义新字段的地方,但它只包含以下内容:
<?php
  class Account extends AppModel {
    var $name = 'Account';
  }
?>

这让我想知道原始开发人员如何获得要保存的“发布”,即使它似乎没有定义。

有什么我遗漏的,还是需要做的?

最佳答案

每当您对数据库进行任何更改时,请确保您的 app/config/core.php文件调试值为 2。Configure::write('debug', 2);
如果为 0,则不会检测到数据库更改。

关于cakephp 新字段不保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7116922/

相关文章:

php - cakePhp 3 连接两个不相关的 mysql 表(松散相关)

php - 如何获取 Cakephp 的完整当前 url

Cakephp 在组件中使用缓存

php - cakephp 中的 requestAction

cakephp - 在 CakePHP 中使用 AJAX 检索数据

mysql - SQL 连接表 - 它是否需要主键或仅需要唯一键?

cakephp - CakePHP写入缓存时偶尔出现错误警告

cakephp - 为什么Cake PhP Controller 需要索引功能?

php - 如何使用 jQuery 和 CakePHP 更新 <div>?

php - 如何在 CakePHP 2 Travis 集成中自动加载 Composer 包