foreach正在丢失对象的值

所以这是一个完全愚蠢的初学者问题,但是我花了很多时间来调查正在发生的事情,而且我完全没有更多的想法。

我正在尝试从CellLineRepository中获取名为“ Cell”的对象的私有值。吸气剂正在工作,它们正在另一个地方使用。

这是我的foreach的外观:

$all_cell_lines = CellLineRepository::findAll();
$allcells = [];
foreach ($all_cell_lines as $cell) {
    $allcells[] = [
        "CellID" => $cell->getId(),"iPSC-ID" => $cell->getIpscId(),"Lab-ID" => $cell->getLabId(),"altID" => $cell->getaltId(),"project" => $cell->getProject()
    ];
    var_dump($allcells);
}

var_dump()中的$all_cell_lines看起来不错,但是我丢失了“ iPSC-ID”和“ Lab-ID”。

object(CellLine)#9 (79) {
[
  "id": "CellLine":private
]=>
string(1) "1"
[
  "created_date": "CellLine":private
]=>
string(10) "2019-05-22"
[
  "created_by": "CellLine":private
]=>
string(3) "314"
[
  "last_modified_date": "CellLine":private
]=>
string(10) "2019-11-22"
[
  "last_modified_by": "CellLine":private
]=>
string(3) "301"
[
  "tab_type": "CellLine":private
]=>
string(8) "internal"
[
  "lab_id": "CellLine":private
]=>
string(5) "xxx"
[
  "alt_id": "CellLine":private
]=>
string(7) "xxx"
[
  "provider": "CellLine":private
]=>
string(36) "xxx"

var_dump()中的$allcells看起来像这样:

    array(1) {
  [
    0
  ]=>
  array(5) {
    [
      "CellID"
    ]=>
    string(1) "1"
    [
      "iPSC-ID"
    ]=>
    string(0) ""
    [
      "Lab-ID"
    ]=>
    string(0) ""
    [
      "altID"
    ]=>
    string(7) "xxx"
    [
      "project"
    ]=>
    string(3) "xxx"
  }
}

有人有线索吗?

woshiwuchao1 回答:foreach正在丢失对象的值

请尝试这种方式

foreach ($all_cell_lines as $cell) {
$allcells[] = [
    "CellID" => $cell->id,"iPSC-ID" => $cell->ipsc_id,"Lab-ID" => $cell->lab_id,"altID" => $cell->alt_id,"project" => $cell->project
];
var_dump($allcells);

}

尝试使用您在数据库中的字段名称获取

,

哇,这太疯狂了。我使用了其他开发人员的模块,但是他们在ORM中而不是在前端进行了权限检查。 这是我发现的:

  public function getLabId() {
    return perissionCheck('lab_id') ? $this->lab_id : '';
  }

还是谢谢! :)

本文链接:https://www.f2er.com/2814694.html

大家都在问