Trying to get property 'name' of non-object


(fb) #1

Hi guys
Can anyone please tell me why i’m getting this error. This page working properly before this.

Error on this line (view.php)

indent: <td class="text-center">
			<?php echo $project->aircraftType->name;?>
	    </td>

All my view page is not working today…anyone please help me…
Thank you in advance…


(Anil Chaudhari) #2

@fatinbahseis some of the $project must not have aircraftType. Make sure, all the $project have proper aircraftType. or you can check while displaying the data. like

<td class=“text-center”>
<?php if ($project->aircraftType) { ?>
<?php echo $project->aircraftType->name;?>
<?php } ?>
</td>


(fb) #3

Thank you…its work for a moment and then error again…

This error:
syntax error, unexpected ‘endforeach’ (T_ENDFOREACH)

indent: <?php $i=1;
		foreach ($model as $project):?>
		<tr>
            <td class="text-center">
		       <?php if ($project->aircraftType) {?>
		       <?php echo $project->aircraftType->name;?>
	  	       <?php}?>
		    </td>
        <?php
		endforeach;?>

(fb) #4

Its okayy @imanilchaudhari…i get what i want…i just delete all the dummy data in my database…and enter new data…it work…thank you for syour sharing…i will use it for future improvement…