试图获取非对象的属性 - CodeIgniter [英] Trying to get property of non-object - CodeIgniter
问题描述
我正在尝试制作更新表单,即检索所选特定 ID 的数据,并填写表单,以便更新.
I'm trying to make update form, that is going to retrieve the data for the specific ID selected, and fill in the form, so its going to be available for updating.
当我点击特定条目(在我的例子中是产品)上的编辑时,它会将我带到edit_product_view
,但指出错误试图获取非对象的属性" 对于我在表单元素的 set_values
中使用的每个变量.
When I click edit on the specific entry (Product in my case), it takes me to the edit_product_view
, but states the error "Trying to get property of non-object" for every variable that I use in set_values
of the form elements.
使用 print_r
,我得到了正确的关联数组,因此它被正确传递.
Using print_r
, I get the correct associative array, so it's passed correctly.
这是我的edit_product_view
的摘录.
<h2><?php echo $heading; ?></h2>
<hr>
<table id="newproduct">
<?php echo form_open('products/edit/'.$product->id); ?>
<tr>
<td class="label"><?php echo form_label('Name:');?></td>
<td><?php echo form_input('prodname', set_value('prodname', $product->prodname));?></td>
</tr>
<tr>
<td class="label"><?php echo form_label('Product Type:');?></td>
<td><?php echo form_dropdown('ptname_fk', $product_types, set_value('ptname_fk', $product->ptname_fk));?></td>
</tr>
$product
是保存所有键值对的数组,但由于某种原因我无法填写表单.
$product
is the array holding all the key-value pairs, but I cannot fill the form for some reason.
先谢谢你!
推荐答案
要访问数组中的元素,请使用数组表示法:$product['prodname']
To access the elements in the array, use array notation: $product['prodname']
$product->prodname
是对象表示法,只能用于访问对象的属性和方法.
$product->prodname
is object notation, which can only be used to access object attributes and methods.
这篇关于试图获取非对象的属性 - CodeIgniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!