0
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
от модели Roomtypes> 0 из room_types
в модели Bookings, перед отправкой формы, если пользователь отправить форму он должен получить флэш-meassage говоря «это номер полны» получаю эту ошибку, как решить эту ошибку при полученииYii2: Попытка получить свойство необъектных
в 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 объект?. Код $ roomtype -> $ totalremain сам по себе не имеет смысла. Если $ roomtype является объектом, тогда он должен быть как $ roomtype-> totalremain. Может быть, условие должно быть переписано, как if ($ totalremain-> totalremain> 0) –
if ($ totalremain-> totalremain> 0) дает ошибку Попытка получить свойство не-объекта – JKLM
'$ roomtype' is the room_type от модели, которая будет выбрана пользователем в форме из раскрывающегося списка – JKLM