Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Foreign Key to Value in View
  • Hi, This must be so simple. I just want to render the foreign key 'category_id" as text from "category_name".
    <h2>Listing Products</h2>
    <br>
    <?php if ($products): ?>
    <table class="zebra-striped">
     <thead>
      <tr>
       <th>Product</th>
       <th>Description</th>
       <th>Category</th>
       <th></th>
      </tr>
     </thead>
     <tbody>
    <?php foreach ($products as $product): ?>  <tr>
    
       <td><?php echo $product->product_name; ?></td>
       <td><?php echo $product->product_description; ?></td>
       <td><?php echo $product->category_id; ?></td>
       <td>
        <?php echo Html::anchor('products/view/'.$product->id, 'View'); ?> |
        <?php echo Html::anchor('products/edit/'.$product->id, 'Edit'); ?> |
        <?php echo Html::anchor('products/delete/'.$product->id, 'Delete', array('onclick' => "return confirm('Are you sure?')")); ?>
    
       </td>
      </tr>
    <?php endforeach; ?> </tbody>
    </table>
    

    Thanks.
  • You mean you have a category model that is related to products? Is this an ORM question? In that case, if your relations are ok, $product->category->name should work fine.
  • Thank you WanWizard. Sorry, this was using the ORM via scaffold. Works perfectly now. <?php echo $product->categories->category_name; ?> Very much appreciated.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion