gpt4 book ai didi

php - Yii 框架数据库中的新列未显示在 $model->getAttributes() 方法调用的输出中?

转载 作者:行者123 更新时间:2023-11-29 08:22:26 25 4
gpt4 key购买 nike

Yii 版本 1.1.8

我在 mysql 数据库的表中添加了一列,但新列未显示在 $model->getAttributes() 方法调用的输出中

我删除了 protected/runtime 文件夹中的所有文件,但仍然没有列

config: 'schemaCachingDuration' => 0,//以秒为单位。 <1表示关闭

我可以直接在数据库中将数据添加到新列。

我还可以做其他事情来调试这个吗?

index.php

<?php

// change the following paths if necessary
$yii=dirname(__FILE__).'/../../framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';

// remove the following line when in production mode
//debug
defined('YII_DEBUG') or define('YII_DEBUG',true );
//show profiler
defined('YII_DEBUG_SHOW_PROFILER') or define('YII_DEBUG_SHOW_PROFILER',true);
//enable profiling
defined('YII_DEBUG_PROFILING') or define('YII_DEBUG_PROFILING',true);
//trace level
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',0);
//execution time
defined('YII_DEBUG_DISPLAY_TIME') or define('YII_DEBUG_DISPLAY_TIME',false);

require_once($yii);
Yii::createWebApplication($config)->run();

main.php

<?php
return CMap::mergeArray(array(
'timeZone'=>'UTC',
'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
'catchAllRequest' => null, // null if online, array('site/offline') if offline,
'sourceLanguage' => 'en_ca',
'theme' => 'td',
'charset' => 'UTF-8',
'preload' => array('log'),
'import' => array(
'application.models.*',
'application.components.*',
'application.extensions.*'
),
'modules' => array(
),
// application components
'components' => array(
'format' => array(
),
'user' => array(
// enable cookie-based authentication
'allowAutoLogin' => true,
'autoRenewCookie' => true,
),
'widgetFactory' => array(
'enableSkin' => true,
),
'urlManager' => array(
),
),
'db' => array(
'class' => 'CDbConnection',
'connectionString' => 'mysql:host=localhost;dbname=mydb',
'emulatePrepare' => true,
'initSQLs'=>array("set time_zone='+00:00'"),
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'tablePrefix' => 'tbl_',
'enableParamLogging' => true, //show parameter values in log
// 'schemaCachingDuration' => 0, // in seconds. <1 means off
'enableProfiling' => YII_DEBUG_PROFILING, //show sql profile info in log
'nullConversion' => true,
//'initSQLs'=>array('set time_zone="+00:00"')
),
'errorHandler' => array(
),
'log' => array(
'class' => 'CLogRouter',
'routes' => array(
array(
'class' => 'CFileLogRoute',
'levels' => 'error, warning',
'filter' => 'CLogFilter',
'enabled' => !YII_DEBUG
),
array(
'class' => 'CPhpMailerLogRoute',
'levels' => 'error',
'emails' => 'neilmcguigan+tderror@gmail.com',
'filter' => 'CLogFilter',
'enabled' => false,
),
array(
'class' => 'CWebLogRoute', // show log messages on web pages
'enabled' => YII_DEBUG,
'filter' => 'CLogFilter',
//'showInFireBug' => false
),
array(
'class' => 'CProfileLogRoute',
'enabled' => YII_DEBUG,
'showInFireBug' => false
)
),
),
'request' => array(

),
'securityManager'=>array(

)
),
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params' => array(
),
), require(dirname( __FILE__ ) . '/override.php'));

最佳答案

刚刚解决了这个问题 - 我发现新的字段名称需要位于模型的 attributeLabels 函数中

public function attributeLabels()
{
return array(
'id' => 'ID',
'newfield' => 'New Field',
...

如果您像我一样并且模型中有很多自定义代码,请谨慎使用“最好还是更新覆盖整个模型”建议。正如 Sankalp Singha 所建议的,只需复制使用 gii 中的“diff”(绿色部分)并将 attributeLabels 中的部分添加到您的代码中即可。

关于php - Yii 框架数据库中的新列未显示在 $model->getAttributes() 方法调用的输出中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18973927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com