Yii PHP-未定义属性
我正在管理一个基于Yii框架构建的站点,并且非常随机地开始出现以下错误。不太清楚这是怎么发生的,也不知道为什么,因为源头还没有被接触到 谢谢你的帮助。谢谢Yii PHP-未定义属性,php,yii,Php,Yii,我正在管理一个基于Yii框架构建的站点,并且非常随机地开始出现以下错误。不太清楚这是怎么发生的,也不知道为什么,因为源头还没有被接触到 谢谢你的帮助。谢谢 CException Description Property "feature.mobile_hero_img" is not defined. Source File /data/www.zoomiezoom.com/yii/framework/db/ar/CActiveRecord.php(106)
CException
Description
Property "feature.mobile_hero_img" is not defined.
Source File
/data/www.zoomiezoom.com/yii/framework/db/ar/CActiveRecord.php(106)
00094: */
00095: public function __get($name)
00096: {
00097: if(isset($this->_attributes[$name]))
00098: return $this->_attributes[$name];
00099: else if(isset($this->getMetaData()->columns[$name]))
00100: return null;
00101: else if(isset($this->_related[$name]))
00102: return $this->_related[$name];
00103: else if(isset($this->getMetaData()->relations[$name]))
00104: return $this->getRelated($name);
00105: else
00106: return parent::__get($name);
00107: }
00108:
00109: /**
00110: * PHP setter magic method.
00111: * This method is overridden so that AR attributes can be accessed like properties.
00112: * @param string property name
00113: * @param mixed property value
00114: */
00115: public function __set($name,$value)
00116: {
00117: if($this->setAttribute($name,$value)===false)
00118: {
Stack Trace
#0 /data/www.zoomiezoom.com/yii/framework/db/ar/CActiveRecord.php(106): CComponent->__get('mobile_hero_img')
#1 /data/www.zoomiezoom.com/yii/framework/web/helpers/CHtml.php(1624): CActiveRecord->__get('mobile_hero_img')
#2 /data/www.zoomiezoom.com/yii/framework/web/helpers/CHtml.php(1100): CHtml::activeInputField('text', Object(feature), 'mobile_hero_img', Array)
#3 /data/www.zoomiezoom.com/protected/views/feature/_form.php(74): CHtml::activeTextField(Object(feature), 'mobile_hero_img', Array)
#4 /data/www.zoomiezoom.com/yii/framework/web/CBaseController.php(119): require('/data/www.theax...')
#5 /data/www.zoomiezoom.com/yii/framework/web/CBaseController.php(88): CBaseController->renderInternal('/data/www.theax...', Array, true)
#6 /data/www.zoomiezoom.com/yii/framework/web/CController.php(732): CBaseController->renderFile('/data/www.theax...', Array, true)
#7 /data/www.zoomiezoom.com/protected/views/feature/create.php(14): CController->renderPartial('_form', Array)
#8 /data/www.zoomiezoom.com/yii/framework/web/CBaseController.php(119): require('/data/www.theax...')
#9 /data/www.zoomiezoom.com/yii/framework/web/CBaseController.php(88): CBaseController->renderInternal('/data/www.theax...', Array, true)
#10 /data/www.zoomiezoom.com/yii/framework/web/CController.php(732): CBaseController->renderFile('/data/www.theax...', Array, true)
#11 /data/www.zoomiezoom.com/yii/framework/web/CController.php(671): CController->renderPartial('create', Array, true)
#12 /data/www.zoomiezoom.com/protected/controllers/FeatureController.php(71): CController->render('create', Array)
#13 /data/www.zoomiezoom.com/yii/framework/web/actions/CInlineAction.php(32): FeatureController->actionCreate()
#14 /data/www.zoomiezoom.com/yii/framework/web/CController.php(300): CInlineAction->run()
#15 /data/www.zoomiezoom.com/yii/framework/web/filters/CFilterChain.php(129): CController->runAction(Object(CInlineAction))
#16 /data/www.zoomiezoom.com/yii/framework/web/filters/CFilter.php(41): CFilterChain->run()
#17 /data/www.zoomiezoom.com/yii/framework/web/CController.php(983): CFilter->filter(Object(CFilterChain))
#18 /data/www.zoomiezoom.com/yii/framework/web/filters/CInlineFilter.php(59): CController->filterAccessControl(Object(CFilterChain))
#19 /data/www.zoomiezoom.com/yii/framework/web/filters/CFilterChain.php(126): CInlineFilter->filter(Object(CFilterChain))
#20 /data/www.zoomiezoom.com/yii/framework/web/CController.php(283): CFilterChain->run()
#21 /data/www.zoomiezoom.com/yii/framework/web/CController.php(257): CController->runActionWithFilters(Object(CInlineAction), Array)
#22 /data/www.zoomiezoom.com/yii/framework/web/CWebApplication.php(320): CController->run('create')
#23 /data/www.zoomiezoom.com/yii/framework/web/CWebApplication.php(120): CWebApplication->runController('feature/create')
#24 /data/www.zoomiezoom.com/yii/framework/base/CApplication.php(135): CWebApplication->processRequest()
#25 /data/www.zoomiezoom.com/public_html/admin_tae/index.php(13): CApplication->run()
#26 {main}
feature.php的模式
<?php
class feature extends CActiveRecord
{
/**
* The followings are the available columns in table 'feature':
* @var integer $id
* @var integer $feature_name_id
* @var string $display_name
* @var integer $language_id
* @var string $long_blurb
* @var string $short_blurb
* @var string $subhead_text
* @var string $hero_img
* @var string $mobile_hero_img
* @var string $thumb_sm
* @var string $thumb_md
* @var string $thumb_lg
* @var string $link_url
* @var string $link_image
* @var string $link_text
* @var string $buyit_id
* @var string $seo_text
* @var string $meta_description
* @var string $meta_keywords
* @var integer $category_id
* @var integer $sub_cat_id
* @var string $deep_link
* @var string $tracking_id
* @var integer $weight
* @var integer $initial_rating
* @var string $active
* @var string $created
* @var string $modified
*/
/**
* Returns the static model of the specified AR class.
* @return CActiveRecord the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'feature';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('feature_name_id', 'required'),
array('feature_name_id, language_id, category_id, sub_cat_id, weight, initial_rating', 'numerical', 'integerOnly'=>true),
array('active', 'length', 'max'=>1),
array('display_name, long_blurb, short_blurb, subhead_text, page_title, hero_img, mobile_hero_img, thumb_sm, thumb_md, thumb_lg, link_url, link_image, link_text, buyit_id, seo_text, meta_description, meta_keywords, deep_link, tracking_id, created', 'safe'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
// 'VarName'=>array('RelationType', 'ClassName', 'ForeignKey', ...additional options)
return array(
'feature_name' => array(self::BELONGS_TO, 'feature_name', 'feature_name_id', 'alias'=>'feature_name'),
'language' => array(self::BELONGS_TO, 'language', 'language_id', 'on'=>'t.language_id = language.id', 'alias'=>'language'),
'category' => array(self::BELONGS_TO, 'category', 'category_id', 'alias'=>'category'),
'sub_cat' => array(self::BELONGS_TO, 'sub_cat', 'sub_cat_id'),
'language_r' => array(self::BELONGS_TO, 'language', 'language_id', 'alias'=>'language'),
);
}
/**
* @return array Named Scopes.
*/
public function scopes()
{
return array(
'active'=>array(
'condition' => 't.active="y"',
'order' => 'feature_name.type_id DESC, category_id, sub_cat_id, t.weight ASC',
),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'Id',
'feature_name_id' => 'Feature Name ID',
'display_name' => 'Display Name',
'language_id' => 'Language',
'long_blurb' => 'Main Description',
'short_blurb' => 'Short Blurb',
'subhead_text' => 'Subhead Text',
'page_title' => 'Browser Title',
'hero_img' => 'Hero Img',
'mobile_hero_img' => 'Mobile Hero Img',
'thumb_sm' => 'Small Thumbnail',
'thumb_md' => 'Medium Thumbnail ',
'thumb_lg' => 'Large Thumbnail',
'link_url' => 'CTA Link Url',
'link_image' => 'CTA Link Image',
'link_text' => ' CTA Link Text',
'buyit_id' => ' BuyIt Link Product ID',
'seo_text' => 'SEO Copy',
'meta_description' => 'Meta Description',
'meta_keywords' => 'Meta Keywords',
'category_id' => 'Category',
'sub_cat_id' => 'Sub Category',
'deep_link' => 'Deep Link',
'tracking_id' => 'Tracking ID',
'weight' => 'Weight',
'initial_rating' => 'Initial Rating',
'active' => 'Active',
'created' => 'Created Date',
'modified' => 'Modified Date',
);
}
}
我猜您正在尝试访问扩展CActiveRecord的模型的属性
这意味着:
或者您已经定义了此属性(mobile\u hero\u img),现在它已被删除
或
您通过从表(模型类所关联的表)中删除列(mobile\u hero\u img)来更改数据库架构。这看起来像是数据库字段中的问题
您是否在表单中添加了一个新的输入字段“mobile\u hero\u img”,而没有将该字段添加到数据库中?请提供“功能”表的模式。以下是您的线索:
您指向的是要素模型中不存在的字段
就在模型里。是在要素表中,并且您是否指向表单中的正确模型。如果您设置了字段的(文本)类型,并且在模型中定义属性时,您可能已将其定义为布尔值或整数,则也可能出现“属性n未定义”问题
例如,下面的文本类型属性错误
* @property boolean $billing_address
正确的定义将是
* @property string $billing_address
有时会有一个小错误,需要花费数小时来追踪。对于每个为“属性未定义”问题而挣扎的人,我有一个建议:检查模型的规则()
定义和框架的版本,因为Yii(1.1.16)中引入了一个bug如果属性列表末尾有额外空间,则会导致此错误:
// author_id WILL NOT WORK!!
array('app_id, group_id, author_id ', 'required'),
这在Yii 1.1.17中已修复。我也有相同的问题。模特课上的一切都很完美,但问题仍然存在。重新启动服务器或SQL不起作用。最后,我清除了protected/runtime/cachexxxx.db文件,然后一切正常。
我用migrate file修改了这些表,有时会出错,所以可能是混合了一些东西。我的问题在升级到yii 1.1.17时得到了解决
数据库保持不变。相关表是否有名为mobile\u hero\u img的列?在模型类的何处使用此属性(如果存在)。添加了feature.php。现在正在获取模式。谢谢你的帮助!网站前端没有任何更改。如果该表被删除,我是否会丢失所有相关的图像?是否该字段用于处理图像上载,然后保存?在这种情况下,必须将mobile_hero_img定义为要素类中的公共属性。你能提供数据库模式吗?(只运行descripe特性)这是PHPDoc,它与实际的模型属性和使用的db列没有任何关系。
// author_id WILL NOT WORK!!
array('app_id, group_id, author_id ', 'required'),