我试图弄清楚为什么我在这一行的视图中得到一个未定义的索引:
<?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);
} ?>
编辑 :
我试图弄清楚为什么我的第一个下拉列表没有显示正确的值。盟友列表 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>