Yii2:尝试获取非对象的属性


Yii2:Trying to get property of non-object

public function actionCreate()
    {
        $model          = new Bookings();
        $temp           = new RoomTypes();
        if ($model->load(Yii::$app->request->post())) 
        {
            $roomtype = $model->room_type;
            $totalremain = RoomTypes::find('total_remain')->where(['room_type' => $model->room_type])->one();
            if ($roomtype->$totalremain > 0) 
            {
                    $imageName   = $model->first_name;
                    $mobile      = $model->primary_mobile;
                    $model->file = UploadedFile::getInstance($model, 'file');
                    $model->file->saveAs('uploads/id_images/' . $imageName . '_' . $mobile . '.' . $model->file->extension);
                    //save the path in the db column
                    $model->id_image = 'uploads/id_images/' . $imageName . '_' . $mobile . '.' . $model->file->extension;
                    $model->save();   
                    return $this->redirect(['view', 'id' => $model->id]);
            } 
                else 
                {
                    echo "This room Types are full ";
                }
        }
        else {
            return $this->render('create', [
                'model' => $model,
                'temp'  => $temp,
            ]);
        }
    }

我需要检查房间类型模型中的total_remain是否>预订模型中的room_types中的 0,在提交表单之前,如果用户提交表单,它应该会得到快速测量,说"这个房间已满"收到此错误,如何解决此问题

if ($roomtype->$totalremain > 0)时出错

房型型号

<?php
namespace backend'models;
use Yii;

/**
 * This is the model class for table "room_types".
 *
 * @property integer $id
 * @property integer $room_id
 * @property string $room_type
 * @property integer $total_count
 * @property string $description
 * @property integer $extra_beds
 * @property string $images
 * @property string $status
 * @property integer $rate
 * @property integer $adults_count
 * @property integer $child_count
 * @property integer $total_people
 */
class RoomTypes extends 'yii'db'ActiveRecord
{
    /**
     * @inheritdoc
     */
    public $imageFiles;
    public static function tableName()
    {
        return 'room_types';
    }
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['room_id','total_booked','total_remain','total_count', 'extra_beds', 'rate', 'adults_count', 'child_count'], 'integer'],
            [['status'], 'string'],
            [['imageFiles'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg', 'maxFiles' => 4,'skipOnEmpty' => true, 'on' => 'update-photo-upload'],
            [['room_type'], 'string', 'max' => 40],
            [['description'], 'string', 'max' => 300],
            [['images'], 'string', 'max' => 500]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'room_id' => 'Room Number',
            'room_type' => 'Room Type',
            'total_count' => 'Total Count',
            'description' => 'Description',
            'extra_beds' => 'Extra Beds',
            //'images' => 'Images',
            'status' => 'Status',
            'rate' => 'Rate',
            'adults_count' => 'Adults Count',
            'child_count' => 'Child Count',
            'total_remain' =>'Remaing Rooms',
            'total_booked' => 'Total Rooms Booked',
        ];
    }
}

如果 ($roomtype->$totalremain> 0( 导致问题的代码。像 if 一样更改它 ($totalremain->total_remain> 0(