我使用ajax从服务器调用返回字符串数据的方法。但是我收到以下错误。
PHP注意'yii \ base \ ErrorException',消息'试图获取 非对象的属性
可能此行$first_day=$row->tblStaff2->first_day_service;
会出错。
public function actionGet_loyalty() {
$model = \common\models\staffs\TblStaff::find()->joinWith('tblStaff2')->all();
$string = "<table class='table table-striped'><tr><th>Name</th><th>Number of Years</th></tr>";
foreach ($model as $row) {
$first_day=$row->tblStaff2->first_day_service;
$midname = ucwords($row->midname);
$name = ucwords($row->firstname) . " " . $midname[0] . ". " . ucwords($row->lastname);
$string.="<tr>"
. "<td>" . $name . "</td>"
. "<td>" . $first_day . "</td>"
. "</tr>";
}
$string.="</table>";
return $string;
}
TblStaff关系
public function getTblStaff2() {
return $this->hasOne(TblStaff2::className(), ['staff_id' => 'id']);
}
答案 0 :(得分:0)
我修改了你的代码。在下面找到它
<tr ng-repeat="user in users">
<td>{{ user.grade }}</td>
<td>{{ user.Email }}</td>
<td>{{ user.contact }}</td>
<td>
<button ng-click="setGrade(user)">
Click me to choose this user
</button>
</td>
</tr>
您可以删除我在工作时添加的评论。