我试图从我的数据库中获取价值。但是所有的时间都告诉我
尝试获取非对象的属性
我确定我的控制器中有这个属性,在我的视图中发送,然后我想显示它。但我不能 下面是我的控制器功能,它是我控制器的一部分。
$car_reservation = CarReservation :: find() -> all();
$projects=Project::find()
//->select(SAAS.'project.*')
// ->joinWith('projectMembers')
//->where(SAAS.'project_member.user_id='.Yii::$app->user->id.' ')
->orderBy('project_title ASC')
->all();
$users = User::find()->all();
return $this->render($render, array('users'=>$users,'car_reservation'=>$car_reservation,'projects'=>$projects,'cars'=>$cars,'rooms'=>$rooms,'today' => $today, 'minute_list' => $minute_list, 'hours_list' => $hours_list, 'status' => $status, 'tasks' => $tasks, 'taskstatuses' => $taskstatus));
}
然后我想在视野中展示它。
<form action="javascript:void(0)" enctype="multipart/form-data" id="cars-edit-modal">
<div class="modal-body">
<div class="tab-content">
<div role="tabpanel" class="tab-pane active">
<div class="row" >
<div class="col-sm-6" >
<?= Yii::t('app','Select car') ?>
</div>
<div class="col-sm-12 mt10 p0i" >
<select class="form-control" name="car_id" data-rel="chosen-car" id="modal-car" data-placeholder="-
<?= Yii::t('app','select') ?>-" >
<option value="
<?= $car->car_name ?>" >-
<?= Yii::t('app','select') ?>-
</option>
<?php
foreach($cars as $cr) { ?>
<option value='
<?= $cr->car_name ?>;'>
<?= $cr->car_name ?>
</option>
<?php } ?>
</select>
</div>
<div class="col-sm-12 mt10 p0i" >
<textarea class="modal-input-button form-control" value="
<?= $car_reservation->car_reservation_note ?>" name="text_car_edit" id="modal-cars" data-placeholder="-
<?= Yii::t('app','Put a note') ?>-" >
</textarea>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer pull-left w100p">
<div class="col-sm-1 mt10 text-right" >
<input type="hidden" name="_csrf" value="
<?=Yii::$app->request->getCsrfToken()?>" />
<button type="submit" class="btn btn-primary">
<?= Yii::t('app','Save') ?>
</button>
</div>
</div>
</form>
</div>
我很困惑,因为yii不知道$ car_reservation的属性。
答案 0 :(得分:0)
尝试
$car_reservation = CarReservation::find()->all();
and var_dump( $car_reservation)
and check is you get the models and the name you used in view match
您可以通过
获得预订汽车的结果$car_reservation = CarReservation :: find() -> all();
all()获取一个集合,但是你在视图中引用了这个集合,就好像它们是一个......
尝试
$car_reservation = CarReservation :: find() ->one();
或者如果您需要管理集合,请使用foreach
正确完成答案 1 :(得分:0)
尝试获取非属性对象错误基本上是通过以下三种方式之一触发的:
1) If you get empty result and u print that empty result.
2) If your result in array and you put object for getting particular property from result.
3) If your result in object and you put array sign for getting particular property.
I prefer you to please print the $car_reservation in controller first.
答案 2 :(得分:-1)
在这里,您使用了<?= $car->car_name ?>" >
<?= $cars->car_name ?>" >
的{{1}}。我可以看到,当您在视图中退出时,您会通过cars
而不是car
,所以请更改它并运行代码。