Custom block not working

Permalink
Hello so I am trying to build a block that is just an image, with a text overlay that is basically just a link however I can only get the image to show and not the text... this is what I have so far...

controller.php
<?php defined('C5_EXECUTE') or die(_("Access Denied."));
class ImagesBlockController extends BlockController {
    protected $btTable = "btImage";
   protected $btInterfaceWidth = "350";
   protected $btInterfaceHeight = "200";
   public function getBlockTypeName() {
      return t('Image');
   }
   public function getBlockTypeDescription() {
      return t('Image block with title');
   }
}


add.php
<?php defined('C5_EXECUTE') or die(_("Access Denied.")) ?>
<?php $al = Loader::helper('concrete/asset_library'); ?>
<p>This is for a landscape image with a click through link!</p>
<?php echo $form->label('content', t('Title')) ?>
   <?php echo $form->text('content') ?>
<?php echo $al->file('ccm-b-file', 'fID', t('Choose File'), $bf); ?>
<?php $bf = File::getByID($fID); ?>


edit.php
<?php echo $form->label('content', 'Name');?>
<?php echo $form->text('content', $content, array('style' => 'width: 300px'));?>
<?php
$al = Loader::helper('concrete/asset_library');
$bf = File::getByID($fID);
echo $al->file('ccm-b-file', 'fID', t('Choose File'), $bf);
?>


view.php
<?php defined('C5_EXECUTE') or die(_("Access Denied.")) ?>
<div class="content">
   <?php echo $content ?>
</div>
<?php
   $file = File::getByID($fID);
   $filePath = $file -> getVersion() -> getRelativePath();
?>
<div class="container">
   <?php
   echo '<img class="img" src="' . $filePath . '" /> '; 
   ?>
</div>


Can anyone help and try to explain why the text from my text field isnt showing when I press save?

Thanks,

Joshua

 
hutman replied on at Permalink Reply
hutman
This all looks like it should work, what does your db.xml file look like? Do you have a text field called content in your table?
joshuabrand replied on at Permalink Reply
Thanks for the fast reply!

my db.xml file is

<?xml version="1.0"?>
<schema version="0.3">
   <table name="btImage">
      <field name="bID" type="I">
         <key />
         <unsigned />
      </field>
      <field name="fID" type="I">
         <unsigned />
      </field>
      <field name="content" type="X2">
      </field>
   </table>
</schema>
hutman replied on at Permalink Reply
hutman
After you have selected an image and entered some content if you go back into the block to edit is the content populated there?
joshuabrand replied on at Permalink Reply
The image is yeah, but the text isnt...
hutman replied on at Permalink Reply
hutman
If you add text from the edit screen and then save and go back in is it there? It seems like the text isn't getting saved to the database, which is why you can't access it from the edit screen and it's not displaying in the output.
joshuabrand replied on at Permalink Reply
No, it's not there when I do that either...

Do you know how I would go about making it so it is getting put into the database? This is the first block I've ever tried so I don't really know too much about what I'm doing...

Thanks!
hutman replied on at Permalink Reply
hutman
What version of Concrete5 are you using?

I've seen similar problems in the Forums for people using 5.6.3.1.

If you can login to your phpMyAdmin and look at the btImages table and see if the content field has stuff in it you would know if it is not saving or if it is not being made available out of the database.

If it's not being saved you could try adding this function to your controller.php.

public function save($args) {
   $args['fID'] = empty($args['fID']) ? 0 : $args['fID'];
   $args['content'] = trim($args['content']);
   parent::save($args);
}


If it is being saved you could try adding this function to your controller.php.

public function on_start() {
   $this->set('content', $this->content);
}
joshuabrand replied on at Permalink Reply
I've got the newest as I only installed it today!

When i go onto phpMyAdmin it says that there is nothing in the btImage table? not even when I have an image displaying on my webpage?

I will try and add that into my controller now and let you know what happens
joshuabrand replied on at Permalink Reply
Still hasn't worked even after adding that to my controller
hutman replied on at Permalink Reply
hutman
Do you have this block within a package or just in the blocks folder? Also, was all of this code in place when you installed the block or did you add some afterward? You might need to go into the Block Types area of the Dashboard, find your block and Refresh it.
joshuabrand replied on at Permalink Reply
I've managed to get it working now... all I did was change the name from Image to Pic.... obviously for some reason you're not allowed to call your own ones Image!

Anyways, thanks for everything!!
Responsive replied on at Permalink Reply
Responsive
you mentioned with a text overlay .... might be a CSS issue ?
joshuabrand replied on at Permalink Reply
I haven't added the css overlay yet, so I can't see this being the issue...