报错:Using $this when not in object context. 模型类用gii生成,原文如下:
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "resources".
*
* @property integer $internalid
* @property integer $resourcetype
* @property string $publicid
* @property integer $parentid
*
* @property Attachedfiles[] $attachedfiles
* @property Changes[] $changes
* @property Dicomidentifiers[] $dicomidentifiers
* @property Maindicomtags[] $maindicomtags
* @property Metadata[] $metadatas
* @property Patientrecyclingorder[] $patientrecyclingorders
* @property Resources $parent
* @property Resources[] $resources
*/
class Resources extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'resources';
}
/**
* @return \yii\db\Connection the database connection used by this AR class.
*/
public static function getDb()
{
return Yii::$app->get('db2');
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['resourcetype', 'publicid'], 'required'],
[['resourcetype', 'parentid'], 'integer'],
[['publicid'], 'string', 'max' => 64],
[['parentid'], 'exist', 'skipOnError' => true, 'targetClass' => Resources::className(), 'targetAttribute' => ['parentid' => 'internalid']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'internalid' => 'Internalid',
'resourcetype' => 'Resourcetype',
'publicid' => 'Publicid',
'parentid' => 'Parentid',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getAttachedfiles()
{
return $this->hasMany(Attachedfiles::className(), ['id' => 'internalid']);
}
}
目测跟你贴的代码没啥关系,检查下当前请求下在哪里用到的$this,可以通过报错页面找具体哪里抛出的异常
一路趟着雷过河,后面的跟紧了