从 ::find 访问数组并添加值
access array from ::find and add values
我需要从 $newFeatured[] = games::find
访问数据,然后在其中添加值 label
。
在控制器中:
foreach ($used_games as $game_id) {
$newFeatured[] = games::find(array(
"conditions" => "id = '$game_id'",
"columns" => "id, filetype "
));
if (in_array($newFeatured->id, $new_games))
{ $newFeatured->label = 'new'; }
else
{ $newFeatured->label = 'featured'; }
}
$this->view->newFeatured = $newFeatured;
$newFeatured->id
无效。我怎样才能访问它?
$newFeatured->label
也不起作用。
在View中需要这样访问
foreach ($newFeatured as $hra) {
echo $hra['0']->filetype."and".$hra['0']->label;
}
您按如下方式在数组中获取结果:
$newFeatured[] = games::find(array(
"conditions" => "id = '$game_id'",
"columns" => "id, filetype "
));
并试图抓住 $newFeatured->id 这对我来说似乎是错误的。
尝试将其作为简单变量获取(不是数组)然后看看会发生什么,如下所示:
$newFeatured = games::find(array(
"conditions" => "id = '$game_id'",
"columns" => "id, filetype "
));
试试这个:
foreach ($used_games as $game_id) {
$newFeatured[] = games::find(array(
"conditions" => $game_id, //returns only id coming from as $game_id of your foreach
"columns" => "filetype " //this one to filetype
));
if (in_array($newFeatured['conditions'], $new_games))
{ $newFeatured['label'] = 'new'; }
else
{ $newFeatured['label'] = 'featured'; }
}
$this->view->newFeatured = $newFeatured;
在控制器中
$newFeatured = array();
foreach ($used_games as $k => $game_id) {
$newFeatured[$k] = games::findFirst(array(
"conditions" => "id = '$game_id'",
"columns" => "id, filetype "
));
if (in_array($newFeatured[$k]->id, $new_games)) {
$newFeatured[$k]->label = 'new';
} else {
$newFeatured[$k]->label = 'featured';
}
}
$this->view->newFeatured = $newFeatured;
查看页面
foreach ($newFeatured as $hra) {
echo $hra->filetype . " and " . $hra->label;
}
我需要从 $newFeatured[] = games::find
访问数据,然后在其中添加值 label
。
在控制器中:
foreach ($used_games as $game_id) {
$newFeatured[] = games::find(array(
"conditions" => "id = '$game_id'",
"columns" => "id, filetype "
));
if (in_array($newFeatured->id, $new_games))
{ $newFeatured->label = 'new'; }
else
{ $newFeatured->label = 'featured'; }
}
$this->view->newFeatured = $newFeatured;
$newFeatured->id
无效。我怎样才能访问它?
$newFeatured->label
也不起作用。
在View中需要这样访问
foreach ($newFeatured as $hra) {
echo $hra['0']->filetype."and".$hra['0']->label;
}
您按如下方式在数组中获取结果:
$newFeatured[] = games::find(array(
"conditions" => "id = '$game_id'",
"columns" => "id, filetype "
));
并试图抓住 $newFeatured->id 这对我来说似乎是错误的。 尝试将其作为简单变量获取(不是数组)然后看看会发生什么,如下所示:
$newFeatured = games::find(array(
"conditions" => "id = '$game_id'",
"columns" => "id, filetype "
));
试试这个:
foreach ($used_games as $game_id) {
$newFeatured[] = games::find(array(
"conditions" => $game_id, //returns only id coming from as $game_id of your foreach
"columns" => "filetype " //this one to filetype
));
if (in_array($newFeatured['conditions'], $new_games))
{ $newFeatured['label'] = 'new'; }
else
{ $newFeatured['label'] = 'featured'; }
}
$this->view->newFeatured = $newFeatured;
在控制器中
$newFeatured = array();
foreach ($used_games as $k => $game_id) {
$newFeatured[$k] = games::findFirst(array(
"conditions" => "id = '$game_id'",
"columns" => "id, filetype "
));
if (in_array($newFeatured[$k]->id, $new_games)) {
$newFeatured[$k]->label = 'new';
} else {
$newFeatured[$k]->label = 'featured';
}
}
$this->view->newFeatured = $newFeatured;
查看页面
foreach ($newFeatured as $hra) {
echo $hra->filetype . " and " . $hra->label;
}