I’m using CakePHP version 4. The add.php view in the Mealplans controller consists of several foreach statements which all look something like this:
<?php
foreach ($tiles as $tile):
if ($user_id == $tile->user_id){
?>
<div id="draggable<?php echo $tile->id; ?>" class="draggable_meal">
<div class="calorie_icon"><?php echo $tile->cals_per_serving; ?> CALS</div>
<span><?php echo $tile->short_description; ?></span>
<?php
echo $this->Form->hidden('cals_per_serving'. $tile->id, [
'multiple' => 'true',
'value' => $tile->cals_per_serving,
]);
} //end if
endforeach;
?>
</div>
I looked over my code to see if I had forgotten a foreach statement somewhere but they’re all there so the singular $tile instead of the plural $tiles should work.
I get the error:
Column not found: 1054 Unknown column ‘Tile.cals_per_serving’ in ‘order clause’
It executes the following query:
SELECT Tiles.id AS Tiles__id, Tiles.cat_id AS Tiles__cat_id, Tiles.short_description AS Tiles__short_description, Tiles.cals_per_serving AS Tiles__cals_per_serving, Tiles.user_id AS Tiles__user_id FROM tiles Tiles ORDER BY Tile.cals_per_serving DESC
Note that in the ORDER BY clause it displays Tile.cals_per_serving and not Tiles.cals_per_serving with an appended s.