Using link selector in custom block

Permalink
Hello.

I'm totally new to PHP and currently trying to build a custom block. So far I've managed to include an image selector successfully.

But trying to include a link selector proves to be quite the challenge. I've read all threads on this forum on this subject I could find and I tried to look at the Image block and find out how the link selector is done there. But somehow it doesn't even seem to write anything to the database. All the other fields in the form get written to the database just fine. I really hope one of you guys can point me in the right direction.

controller.php:
<?php
namespace Application\Block\Mitarbeiter;
use Concrete\Core\Block\BlockController;
use Core;
defined('C5_EXECUTE') or die(_("Access Denied."));
class Controller extends BlockController
{
    protected $btTable = "btMitarbeiter";
    protected $btInterfaceWidth = "350";
    protected $btInterfaceHeight = "240";
    protected $btDefaultSet = 'basic';
    public function getBlockTypeName()
    {
        return t('Mitarbeiter');
    }

form.php (I use a form.php for add.php and edit.php like seen in other blocks
<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
?>
<?php
if ($fID > 0) {
    $fo = File::getByID($fID);
    if ($fo->isError()) {
        unset($fo);
    }
}
?>
<div class="form-group">
  <?php echo $form->label('fID', t('Bild'));?>
  <?php
    $al = Loader::helper('concrete/asset_library');


view.php:
<?php defined('C5_EXECUTE') or die(_("Access Denied.")) ?>
<li>
  <?php echo $image ?>
  <div class="name">
    <h1><?php echo $name ?></h1>
    <h2><?php echo $titel ?></h2>
    <div class="telefon">Mobil: <a href="tel:<?php echo $mobile ?>"><?php echo $mobile ?></a><br>
    Tel: <a href="tel:<?php echo $festnetz ?>"><?php echo $festnetz ?></a></div>
    <a href="<?php echo $linkURL ?>" class="questions">Mehr zum Mitarbeiter</a>
  </div>
</li>


and my db.xml

<?xml version="1.0"?>
<schema version="0.3">
   <table name="btMitarbeiter">
      <field name="bID" type="I">
        <key />
        <unsigned />
      </field>
      <field name="fID" type="I">
        <unsigned />
        <default value="0" />
      </field>
      <field name="name" type="C"></field>
      <field name="titel" type="C"></field>
      <field name="mobile" type="C"></field>
      <field name="festnetz" type="C"></field>

 
LyDiaMo replied on at Permalink Best Answer Reply
LyDiaMo
Please update your blocktype in concrete5, so the database table will be updated and you can be sure, that all fields are in datebase table from these block type.
Open [YOUR_URL]/dashboard/blocks/types and click on your blocktype. Then the refresh button.

And you must add two lines on your controller function getLinkURL()

function getLinkURL() {
       $linkToC = \Page::getByID($this->internalLinkCID);
       if (is_object($linkToC)) {
           return $linkToC->getCollectionPath();
       }
    }
ramonleenders replied on at Permalink Reply
ramonleenders
Refreshing might help indeed. After refreshing, search if this column is in your database table. If that is all true, then var_dump the $_POST values.

public function save($args)
    {
        var_dump($args);
        exit;
        parent::save($args);
    }


Now instead of saving there should be a red box popping up with the post values. See if your value is there with the appropiate key.

Other method:

If you want to do fast and simple block building, you could give block designer a try as well:http://www.concrete5.org/marketplace/addons/block-designer...

I think making blocks like these should be as easy as baking cake with a cake mix ;-)
johnrackles replied on at Permalink Reply
Thanks for your replies. You were right, all I had to do was update the block and add those lines of code, now it works like intended.

Thank you once again for saving me that headache :)