Displaying a product category

Permalink
Hi, I'm following the tutorial in the Concrete5 beginner's guide 'creating your own add-on block'. I've just made the product_information block on page 191 where product categories are available to choose.

The controller:
<?php defined('C5_EXECUTE') or die(_("Access Denied."));
class ProductInformationBlockController extends BlockController {
   protected $btTable = "btProductInformation";
   protected $btInterfaceWidth = "350";
   protected $btInterfaceHeight = "300";
   public function getBlockTypeName() {
      return t('Product Information');
   }
   public function getBlockTypeDescription() {
      return t('Embeds product information in your web page');
   }
   public function view() {
      $this->set('bID', $this->bID);
      $this->set('picture', $this->getPicture());
   }


The view:
<div class="product-information">
   <h2><?php echo $title; ?></h2>
   <?php 
   if($picture instanceof File) { ?>
      <img src="<?php echo $picture->getURL(); ?>" style="max-width: 100%; height: 100%;">
   </div>
   <?php }
   echo $description;
   ?>
</div>


The form setup
$al = Loader::helper('concrete/asset_library'); ?>
<div class="ccm-block-field-group">
   <h2>Title</h2>
   <?php echo $form->text('title', $title, array('style' => 'width: 550px'));  ?>
</div>
<div class="ccm-block-field-group">
   <h2>Picture</h2>
   <?php echo $al->image('ccm-b-image', 'fIDpicture', 'Choose File', $this->controller->getPicture());  ?>
</div>
<div class="ccm-block-field-group">
   <h2>Description</h2>
   <?php Loader::element('editor_config'); ?>
   <?php Loader::element('editor_controls', array('mode' => 'full')); ?>
   <?php echo $form->textarea('description', $description, array('class' => 'ccm-advanced-editor'));  ?>
</div>


db.xml
<?xml version="1.0"?>
<schema version="0.3">
   <table name="btProductInformation">
      <field name="bID" type="I">
         <key />
         <unsigned />
      </field>
      <field name="title" type="C" size="255"></field>
      <field name="description" type="X2"></field>
      <field name="fIDpicture" type="I"></field>
      <field name="categoryID" type="I"></field>
   </table>
   <table name="btProductInformationCategories">
      <field name="categoryID" type="I">
         <autoincrement />


How would I display the name of the chosen category in the view template? I can display the categoryID (1 or 2)so I presume I could use this ID to grab the category name?

 
magpie replied on at Permalink Reply
Ok so this is how I did it:

In my view function in the controller:

$this->set('catID', $this->categoryID);
$this->set('cats', $this->getCategories());


Then in the view file:

foreach ($cats as $k => $v) {
  if($k == $catID) {
    echo $v;
  }
}


There is probably a far easier way of getting the name of the selected category name?