Home >Database >Mysql Tutorial >How to Fix the \'Trying to get property of non-object\' Error in CodeIgniter Form Elements?

How to Fix the \'Trying to get property of non-object\' Error in CodeIgniter Form Elements?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-25 11:44:02425browse

How to Fix the

Non-Object Property Error in CodeIgniter: Why and How to Fix It

When attempting to modify a form with specific data based on an ID, you may encounter the "Trying to get property of non-object" error in CodeIgniter. This occurs when attempting to access variables within the set_values() function of form elements.

The error arises when you try to use object notation ($product->prodname) to access elements within an array ($product). In PHP, arrays use array notation ($product['prodname']) to access their elements.

To address this issue, modify your code as follows:

<code class="php"><?php echo form_input('prodname', set_value('prodname', $product['prodname'])); ?>
<?php echo form_dropdown('ptname_fk', $product_types, set_value('ptname_fk', $product['ptname_fk'])); ?></code>

The above is the detailed content of How to Fix the \'Trying to get property of non-object\' Error in CodeIgniter Form Elements?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn