我試圖找出爲什麼我得到一個未定義的索引視圖中的這一行:未定義指數
<?php if ($allies[''] == 'No Wrestlers In Database') {
控制器:
if (empty($rosterList)) {
$allies[] = 'No Wrestlers In Database';
}
else
{
$allies[] = 'Please Select An Option';
foreach ($rosterList AS $ally)
{
$allies[$ally->id] = $ally->rosterName;
}
}
查看:
<?php if ($allies[''] == 'No Wrestlers In Database') {
echo $allies[''];
}
else {
echo form_dropdown('ally1', $allies, $alliesList->ally1ID);
} ?>
編輯:
我想弄清楚爲什麼我的第一個下拉列表不顯示正確的值。 alliesList的print_r
Array
(
[0] => stdClass Object
(
[id] => 1
[rosterListID] => 1
[ally1ID] => 2
[ally2ID] => 3
[ally3ID] => 2
[ally4ID] => 3
[ally5ID] => 2
)
)
盟友的print_r
Array
(
[0] => Please Select An Option
[1] => Kid Wonder
[3] => Oriel
[2] => Test Character
)
編輯2:
這裏是我造的,但是在說試圖讓非對象的屬性我的視圖文件得到一個錯誤。
//Get member's allies
$alliesList = $this->bios->getRosterAlliesByRosterID($this->session->userdata('defaultRosterListID'));
echo "<pre>";
print_r($alliesList);
echo "</pre>";
// Get list of members
$rosterList = $this->bios->getAllRoster();
$allies = array();
if (empty($rosterList)) {
$allies[''] = 'No Wrestlers In Database';
}
else
{
$allies[''] = 'Please Select An Option';
foreach ($rosterList AS $ally)
{
$allies[$ally->id] = $ally->rosterName;
}
}
echo "<pre>";
print_r($alliesList);
echo "</pre>";
<?php echo form_label('Ally 1', 'ally1'); ?>
<div>
<?php if (in_array('No Wrestlers In Database', $allies)) {
echo 'No Wrestlers In Database';
}
else {
echo form_dropdown('ally1', $allies, $alliesList->ally1ID);
} ?>
</div>
因爲您使用鍵「'''索引到'$ allies',並且數組中沒有這樣的鍵。 – Jon 2012-04-17 15:51:00
我會建議你不要使用空字符串作爲密鑰 – 2012-04-17 15:52:10
[PHP:「Notice:Undefined variable」和「Notice:Undefined index」]的可能重複(http://stackoverflow.com/questions/4261133/php- notice-undefined-variable-and-notice-undefined-index) – Jocelyn 2013-03-29 11:55:26