cakephp新字段不保存 [英] cakephp new field not saving

查看:79
本文介绍了cakephp新字段不保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我只是给了一个CakePHP项目,我试图扩展模型以包括新字段。我原来的开发人员不再可用,我以前没有使用CakePHP。问题是所有其他字段都正确保存,但新字段保存为空字符串。



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

  class_time varchar(30)

我扩展了原始视图以支持新字段

 <?= $ form > input('release',array('type'=>'radio','legend'=> false,'div'=>'radio','options'=& =>'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 PM'=>'6:00-8:30 PM','6:30 -9:00 PM'=>'6:30-9:00 PM')))>

正如我所知,页面正确呈现HTML

 < div class =radio>< input type =hiddenname =data [Account] [release]id =AccountRelease_ value =>< input type =radioname =data [Account] [release]id =AccountReleaseAgreevalue =Agree>< label for =AccountReleaseAgree> ; nbsp;< / label>< input type =radioname =data [Account] [release]id =AccountReleaseDisagreevalue =Disagree>< label for =AccountReleaseDisagree>不同意; / label>< / div> 
< div class =radio>< input type =hiddenname =data [Account] [class_time]id =AccountClassTime_value =>< input type = radioname =data [Account] [class_time]id =AccountClassTimeNoPreferencevalue =No preference>< label for =AccountClassTimeNoPreference>无偏好& nbsp;< / label& =radioname =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 =radioname =data [Account] [class_time]id =AccountClassTime6:30-9:00P.m。 value =6:30-9:00 PM>< label for =AccountClassTime6:30-9:00P.m。> 6:30-9:00 PM< / label>< / div ;

但是当它保存时,它会保存release ,但不是class_time。



从cakePHP文档中可以找到,app / models / account.php是我相信我需要定义新字段,但只包含以下内容:

 <?php 
类帐户扩展AppModel {
var $ name ='Account';
}
?>

这让我想知道原开发者如何获得发布

有没有我缺少的东西,或者还需要做些什么?

解决方案

每当您对数据库进行任何更改时,请确保您的 app / config / core.php 文件调试值2. 配置:: write('debug',2);



如果为0,数据库更改不会


How to you extend a cakePHP project so it can use a new field in the database?

I just given a CakePHP Project that I am trying to extend the model to include a new field. I The original Developer is no longer available, and I haven't worked with CakePHP previously. The problem is that all of the other fields are being saved correctly, but the new field is being saved as an empty string.

The database has been extended to include the new field:

class_time  varchar(30)

I extended the original view to support the new field

<?=$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.')))?>

As near as I can tell, the page is rendering the HTML correctly

<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>

But when it saves, it is saving the selection for the "release" field (and the others), but not the class_time.

From what I can find in the cakePHP documentation, app/models/account.php is where I believe I would need to define the new field, but it only consists of the following:

<?php
  class Account extends AppModel {
    var $name = 'Account';
  }
?>

Which makes me wonder how the original developer got the "release" to save, even though it doesn't appear to be defined.

Is there something that I am missing, or that still needs to be done?

解决方案

Whenever you make any changes to your database, please make sure that your app/config/core.php file debug value is 2. Configure::write('debug', 2);

If it is 0 database changes will not be detected.

这篇关于cakephp新字段不保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆