这是我的控制器代码:
public function edit_manpower($Manpower_id=null)
{
$session = session();
$db = \Config\Database::connect();
$builder = $db->table('Manpower');
$builder->select('Manpower.*');
$builder->where('Manpower_id', $Manpower_id);
$query = $builder->get();
$data['row'] = $query->getResultArray();
return view("admin/update_manpower_form",$data);
}
这是出现错误的视图代码:
<form action = "<?php echo site_url('Admin/updatemanpower/'.$row['Manpower_id']);?>" method=
"post" enctype="multipart/form-data">
<input type="hidden" name="_method" value="PUT"/>
<div class="form-group">
<div class=required-field><label for="Name">NAME:</label></div>
<input type="text" class="form-control" placeholder="Enter name" id="Name" value="<?php echo
$row['Name'];?>" name="Name" autocomplete="off">
</div>
<br>
<div class="form-group">
<div class=required-field><label for="Contact_no">CONTACT NUMBER:</label></div>
<input type="text" class="form-control" placeholder="Enter phone number" id="Contact_no"
value="<?php echo $row['Contact_no'];?>" name="Contact_no" autocomplete="off">
</div>
<br>
当我将下面的行放在视图的顶部时,将显示所需的数据:
<?php var_dump($row); ?>
显示的错误消息为:
Undefined array key "Manpower_id"
APPPATH\Views\admin\update_manpower_form.php at line 65
64 <br><br>
65 <form action = "<?php echo site_url('Admin/updatemanpower/'.$row['Manpower_id']);?>"
method= "post" enctype="multipart/form-data">
66 <input type="hidden" name="_method" value="PUT"/>
我找不到我做错了什么。请帮助我。
1条答案
按热度按时间6vl6ewon1#
$row可能是一个对象数组。#std[]