Trying to get property of non-object error in Yii

后端 未结 1 715
我在风中等你
我在风中等你 2021-01-23 08:02

Case 1: I get an array of CActiveRecords and try to loop over it as shown below:

foreach ($pendingTasks as $task)
    {
        if($task->task->employee_id         


        
相关标签:
1条回答
  • 2021-01-23 08:57

    Because of the tasks in $pendingTasks must not have a relation. You can check by simply adding an isset() like so:

    foreach ($pendingTasks as $task) {
        if(isset($task->task) && $task->task->employee_id=="1") {
            //some logic here
        } else {
            echo "{$task->id} doesn't have a task relation";
        }
    }
    

    Assuming $pendingTasks are instances of TaskLog also.

    0 讨论(0)
提交回复
热议问题