如何在yii框架中显示数据库中新添加的列? [英] how to show new added columns in database in yii framework?

查看:23
本文介绍了如何在yii框架中显示数据库中新添加的列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 db 表中添加了两个新列,然后我在表模型本身中定义了这些新列,然后,当我调用时

i added two new columns in my db table, and then i defined these new columns in the table model itself, and then, when i called

$model->getAttributes()

两个新列没有出现在$model->getAttributes()方法调用的数组输出中

我的配置中没有设置模式缓存,知道如何解决这个问题吗?我将如何获得输入表单的值如果我在展示两个新添加的列时遇到问题,来自前端的新添加的列?

there's no schema caching set in my configs, any idea how to solve this?, and how am I gonna get the value of the input forms of the new added columns from the front-end if i have a problem in showing off the two newly added columns ?

例如

新列内部外屋

//查看

 <?php echo $form->checkBox($model,'INHOUSE',array("id"=>"inhouse","value"=>1, "uncheckValue"=>0));?>
 <?php echo $form->checkBox($model,'OUTHOUSE',array("id"=>"outhouse","value"=>1, "uncheckValue"=>0));?>

//控制器更新动作

我试图保存 INHOUSE 的值,但我这样做时没有保存 OUTHOUSE 的值

i tried to save the value of the INHOUSE and OUTHOUSE didn't get saved when i do

$model->attributes = $_POST['users'];
$model->save();

NOR

$model->INHOUSE = $_POST['users']['INHOUSE'];
$model->OUTHOUSE = $_POST['users']['OUTHOUSE'];
$model->save;

有什么想法可以解决所有这些问题吗?

any ideas how to solve all those problems?

推荐答案

1-您能否将数据直接插入数据库中的那些列?2-您可以在管理视图或任何其他视图中查看这些列吗?3-您可以使用 getColumn 方法检索这些值吗?

1-Can you insert data directly into your DB on those columns? 2-Can you view those columns on the admin view or on any other view? 3-Can you retrieve those values using a getColumn method?

如果没有,试试这个:

确保您在模型和视图中指定了新列

Make sure that you have the new columns specified in your model and view

Model_Name.php

Model_Name.php

public function attributeLabels()
{
    return array(
        'id' => 'ID', // example
        'new_column' => 'New Column',
        ...
    );
}

您还应该从顶部到底部进行检查,作为一种好的做法,您还应该在模型的顶部键入此内容

You should also check from TOP to bottom and as a good practice you should also type this on the top of the model

 * @property integer $id //example
 * @property data_type $new_column
...

然后要查看您的新列,您需要将它们添加到必要的视图中.

Then to view your new columns you need to add them to the necessary views.

示例

VIEW.PHP

$this->widget('zii.widgets.CDetailView', array(
    'data'=>$model,
    'attributes'=>array(
         'id',
         'new_column',
          ...

如果您的模型具有所有这些定义,您应该能够从数据库中检索这些值,请重新检查您可能拥有的任何自定义函数.

If you have your model with all these definitions you should be able to retrieve those values from the DB, re-check any custom functions that you may have.

这篇关于如何在yii框架中显示数据库中新添加的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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