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:
The view:
The form setup
db.xml
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?
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()); }
Viewing 15 lines of 30 lines. View entire code block.
The view:
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>
Viewing 15 lines of 19 lines. View entire code block.
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 />
Viewing 15 lines of 30 lines. View entire code block.
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?
In my view function in the controller:
Then in the view file:
There is probably a far easier way of getting the name of the selected category name?