Php Yii 2框架的问题

Php Yii 2框架的问题,php,yii2,frameworks,Php,Yii2,Frameworks,我试着用YII2写博客,我的框架很难从数据库中调用数据 例如,当我从“用户”表中调用“用户名”时 我收到以下错误:-->>未知属性:app\models\Category::fullname 你能帮我解决这个问题吗?我在哪里犯了错误 这是我的帖子模型,包含: <?php namespace app\models; use Yii; /** * This is the model class for table "post". * * @property integer $i

我试着用YII2写博客,我的框架很难从数据库中调用数据

例如,当我从“用户”表中调用“用户名”时


我收到以下错误:-->>未知属性:app\models\Category::fullname

你能帮我解决这个问题吗?我在哪里犯了错误

这是我的帖子模型,包含:

<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "post".
 *
 * @property integer $id
 * @property integer $user_id
 * @property string $title
 * @property string $description
 * @property string $content
 * @property integer $count_view
 * @property string $status
 * @property string $created_at
 *
 * @property User $user
 * @property TagAssign[] $tagAssigns
 */
class Post extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'post';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'count_view','category_id'], 'integer'],
            [['content', 'status'], 'string'],
            [['created_at'], 'safe'],
            [['count_view'], 'default','value'=>0],
            [['user_id'], 'default','value'=>Yii::$app->user->id],
            [['title', 'description'], 'string', 'max' => 255],
            [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => 'User ID',
            'title' => 'Title',
            'description' => 'Description',
            'content' => 'Content',
            'category' => 'Category',
            'count_view' => 'Count View',
            'status' => 'Status',
            'created_at' => 'Created At',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(Category::className(), ['id' => 'user_id']);
    }

    public function getCategory()
    {
        return $this->hasOne(User::className(), ['id' => 'category_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTagAssigns()
    {
        return $this->hasMany(TagAssign::className(), ['post_id' => 'id']);
    }
}

Post模型中更改此选项

public function getUser()
{
    return $this->hasOne(User::className(), ['id' => 'category_id']);   
}

public function getCategory()
{
    return $this->hasOne(Category::className(), ['id' => 'user_id']);
}

您是否尝试在数据库和小部件中将列重命名为
user\u fullname
Category
user
模型?检查关系名称和属性名称。您的
$model
包含什么?是的,它不工作这是我的模型-->公共函数attributeLabels(){return['id'=>'id'、'user\U id'=>'user id'、'title'=>'title'、'description'=>'description'、'content'=>'content'、'category'=>'category'、'count\u view'=>'count view'、'status'=>'status'、'created\u'=>'created\n'=>'
<?php

namespace app\models;

use Yii;
use yii\web\IdentityInterface;

/**
 * This is the model class for table "user".
 *
 * @property integer $id
 * @property string $username
 * @property string $password
 * @property string $fullname
 * @property string $status
 * @property string $role
 * @property string $created_At
 *
 * @property Post[] $posts
 */
class User extends \yii\db\ActiveRecord implements IdentityInterface
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'user';
    }
public $current_password;
public $new_password;
public $confirm_password;
public $authKey;


    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['status', 'role'], 'string'],
            [['created_At'], 'safe'],
            [['username', 'password', 'fullname'], 'string', 'max' => 45],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
          'username' => 'username',
            'password' => 'password',
            'fullname' => 'fullname',
            'status' => 'Status',
            'role' => 'Role',
            'created_At' => 'Created  At',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getPosts()
    {
        return $this->hasMany(Post::className(), ['user_id' => 'id']);
    }

    public static function findIdentity($id)
    {
        return static::findOne($id);
    }
    public static function findIdentityByAccessToken($token,$type=null)
    {
        return static::findOne(['access_token'=>$token]);
    }
    public function getId()
    {
        return $this->id;
    }
    public function getAuthKey()
    {
        return $this->authKey;
    }
    public function validateAuthKey($authKey)
    {
        return $this->authKey == $authKey;
    }
    public static function findByUsername($username)
    {
        return static::findOne(['username'=>$username]);
    }

    public function validatePassword($password)
    {
        if(Yii::$app->security->validatePassword($password,$this->password))
        {
            return true;
        } else {
            return false;
        }
    }


}
public function getUser()
{
    return $this->hasOne(User::className(), ['id' => 'category_id']);   
}

public function getCategory()
{
    return $this->hasOne(Category::className(), ['id' => 'user_id']);
}