V8.5.4 - Adding Page Selector to Custom Block - driving me bonkers
Permalink
Hi Folks
I have made a Custom Block called Product Advert, its pretty simple, it has an image selector, a Was Price, a Now Price and also a View Product button. Its all working apart from the View Product Button. I just cant seem to get the Internal Link Selector to work.
The database table shows the cID of the page I have chosen so I know its partially working. But maybe I am missing how to convert that to a url? Am I missing a helper class somewhere?
Can anyone help me out? I have tried searching for this in the forums, but cant find anything more recent than 2015. I did find one post but it just doesnt work. I know I am doing something wrong, just dont know what.
Below is my code.
Controller.php
form.php
view.php
db.xml
I have made a Custom Block called Product Advert, its pretty simple, it has an image selector, a Was Price, a Now Price and also a View Product button. Its all working apart from the View Product Button. I just cant seem to get the Internal Link Selector to work.
The database table shows the cID of the page I have chosen so I know its partially working. But maybe I am missing how to convert that to a url? Am I missing a helper class somewhere?
Can anyone help me out? I have tried searching for this in the forums, but cant find anything more recent than 2015. I did find one post but it just doesnt work. I know I am doing something wrong, just dont know what.
Below is my code.
Controller.php
<?php namespace Application\Block\ProductAdvert; defined('C5_EXECUTE') or die(_("Access Denied.")); use Concrete\Core\Block\BlockController; use Core; use Concrete\Core\Page\Page; use Concrete\Core\File\File; class Controller extends BlockController { public $helpers = array('form'); protected $btTable = "btProductAdvert"; protected $btCacheBlockOutput = true; protected $btCacheBlockOutputOnPost = true; protected $btCacheBlockOutputForRegisteredUsers = true; protected $btInterfaceWidth = "450";
Viewing 15 lines of 46 lines. View entire code block.
form.php
<?php defined('C5_EXECUTE') or die("Access Denied."); $app = \Concrete\Core\Support\Facade\Application::getFacadeApplication(); ?> <?php if ($fID > 0) { $fo = File::getByID($fID); if (!is_object($fo)) { unset($fo); } } ?> <div class="form-group"> <?php echo $form->label('productName', t('Page Name'));?> <?php echo $form->text('productName', $productName)?> </div>
Viewing 15 lines of 34 lines. View entire code block.
view.php
<?php defined('C5_EXECUTE') or die(_("Access Denied.")) ?> <a href="<?php echo $linkToC ?>" class="product-link">See Product</a> <div> <div class="promo-text"> <h2><?php echo $productName ?></h2> <p class="was-price">Was £<?php echo $wasPrice ?></p> <p class="now-price">Now £<?php echo $nowPrice ?></p> </div> </div> <div class="promo-image"><?=$image?></div>
db.xml
<?xml version="1.0" encoding="UTF-8"?> <schema xmlns="http://www.concrete5.org/doctrine-xml/0.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.concrete5.org/doctrine-xml/0.5http://concrete5.github.io/doctrine-xml/doctrine-xml-0.5.xsd"&... <table name="btProductAdvert"> <field name="bID" type="integer"> <unsigned/> <key/> </field> <field name="fID" type="integer"> <unsigned/> <default value="0"/> </field> <field name="productName" type="string" size="255"></field> <field name="wasPrice" type="string" size="255"></field> <field name="nowPrice" type="string" size="255"></field> <field name="internalLinkCID" type="integer">
Viewing 15 lines of 20 lines. View entire code block.
<a href="<?php echo Page::getByID($internalLinkCID)->getCollectionPath(); ?>" class="product-link">See Product</a>
Edit: Also, here's a good starting point to learn more! https://documentation.concrete5.org/developers/pages-themes/working-...
Edit Edit:
It looks like your href should actually be <?php echo $this->getLinkURL(); ?>
your getLinkURL() method should look something like...