Custom blocks

Permalink
Hey,

I have a question about creating custom blocks.

This is the code of the 'add.php'
<?php defined('C5_EXECUTE') or die(_("Access Denied.")) ?>
<div class="ccm-ui">
   <div class="alert-message block-message info">
      <?php echo t("Voeg een product toe.") ?>
   </div>
   <?php echo $form->label('categorie', t('Categorie')) ?>
   <?php echo $form->select('categorie', array('Barbecue pakketten' => 'Barbecue pakketten', 'Turkse deegwaren' => 'Turkse deegwaren', 'Belegde broodjes
en lunchroom' => 'Belegde broodjes en lunchroom')); ?>
   <?php echo $form->label('titel', t('Titel')) ?>
   <?php echo $form->text('titel', $titel) ?>
   <?php echo $form->label('sound', t('Uitspraak')) ?>
   <?php echo $form->text('sound', $sound) ?>
   <?php echo $form->label('ondertitel', t('Ondertitel')) ?>
   <?php echo $form->text('ondertitel', $ondertitel) ?>
   <?php echo $form->label('omschrijving', t('Omschrijving')) ?>


I have recently created a block that inserts information into my sql database. The problem however is, when I edit this block and save it, it inserts a new row into the database instead of updating the old one.

The 'add.php' contains the helper that uploads an image. This is inserted into the row. When editing however, the edit form doesn't remember what image is related to the block. The 'edit.php' looks like this.

<?php defined('C5_EXECUTE') or die(_("Access Denied.")) ?>
<div class="ccm-ui">
   <div class="alert-message block-message info">
      <?php echo t("Pas een product aan.") ?>
   </div>
   <?php echo $form->label('categorie', t('Categorie')) ?>
   <?php echo $form->select('categorie', array('Barbecue pakketten' => 'Barbecue pakketten', 'Turkse deegwaren' => 'Turkse deegwaren', 'Belegde broodjes
en lunchroom' => 'Belegde broodjes en lunchroom')); ?>
   <?php echo $form->label('titel', t('Titel')) ?>
   <?php echo $form->text('titel', $titel) ?>
   <?php echo $form->label('sound', t('Uitspraak')) ?>
   <?php echo $form->text('sound', $sound) ?>
   <?php echo $form->label('ondertitel', t('Ondertitel')) ?>
   <?php echo $form->text('ondertitel', $ondertitel) ?>
   <?php echo $form->label('omschrijving', t('Omschrijving')) ?>


If anyone spots the problem, please let me know.

- Jim

 
mnakalay replied on at Permalink Reply
mnakalay
Hello,
Concerning your second problem you need to modify your code like so:
$al = Loader::helper('concrete/asset_library');
$file = empty($afbeelding) ? null : File::getByID($afbeelding);
echo $al->file('afbeelding', 'afbeelding', 'Selecteer foto', $file);


What it does is that if your field 'afbeelding' already has a value (which is just a number id to the file), it gets the file object itself. Otherwise it gives it a null value.
We then assign that value to the field.

Of course for that to work you need to set the variable $afbeelding in your controller by doing
$this->set('afbeelding', $this->afbeelding);


Hope that helped
jimderonde replied on at Permalink Reply
Thanks, this worked for the second problem. Really helped me a lot!
mnakalay replied on at Permalink Reply
mnakalay
You're welcome.
The first problem is not really a problem. It is kind of an intentional behavior. That's what allows to revert a page back to a previous state.