Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
230 views
in Technique[技术] by (71.8m points)

php - Trying to get property of non-object - CodeIgniter

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.

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.

Using print_r, I get the correct associative array, so it's passed correctly.

This is excerpt of my 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 is the array holding all the key-value pairs, but I cannot fill the form for some reason.

Thank you in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To access the elements in the array, use array notation: $product['prodname']

$product->prodname is object notation, which can only be used to access object attributes and methods.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...