HELP! Block from custom package won't drag to page

Permalink
I have created a package that contains a dashboard single page to input the data and a block that will display the data entered.

The package is designed to maintain a list of vets sorted into areas of the UK.

The dashboard page is working but when I try to drag the block onto the page nothing happens... not even an error or anything

I have been puzzling this one for a while... any help greatly appreciated.

P.S I am new to custom block/package development so go easy :)

I have attached the package as a zip.

1 Attachment

sparrowwebservices
 
mnakalay replied on at Permalink Reply
mnakalay
Hello,
I don't know if that will solve the problem but you have to table definition db.xml, one at the package level defining table btVets and another one at the block level. Problem is, the one at the block level defines table btVetsblock but also defines the same table btVets as the package level. That might confuse C5 not knowing which to attach to what?
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi sparrowwebservices,

I think the problem may be that you do not have a block add.php or edit.php.
sparrowwebservices replied on at Permalink Reply
sparrowwebservices
Hi DrKDilkington,

Thanks for your reply. That was my first thought also. However as I was new to block and package development I developed this package using the hw_simple_testimonials block as this uses the same principle. This doesn't have a add or edit.php file in the block directory yet still works.
sparrowwebservices replied on at Permalink Reply
sparrowwebservices
Yes I do. This surely wouldn't stop the block adding to the page though? You would expect an error at least?

Sorry I am new to development. I have based this package on the HW Simple Testimonials package as this applies the same principle. My package is set up in exactly the same way.
mnakalay replied on at Permalink Best Answer Reply
mnakalay
I was able to make it work. You have 2 errors:
First one: In the block's controller at the top you have.
protected $btTable = 'btVets';

It should be
protected $btTable = 'btvetsblock';


Second one: in the block's view file you have
<?php  foreach ($vetlist as $vl) : ?>

it should be
<?php  foreach ($Vetslist as $vl) : ?>

After correcting those 2 things it worked for me
sparrowwebservices replied on at Permalink Reply
sparrowwebservices
Hi mnakalay,

thank you very much

That gets me 50% of the way there but now when I add the block it adds it to the page. As soon as I save or publish the page I get the following exception (I have debugger output turned on):

'Invalid argument supplied for foreach()'

I am getting this on this line in the view.php file (Line 5)

<?php           foreach ($VetsList as $vl) : ?>
sparrowwebservices replied on at Permalink Reply
sparrowwebservices
IGNORE ME.

A silly Typo... you were spot on... Thank you very much mate. I owe you one.
sparrowwebservices replied on at Permalink Reply
sparrowwebservices
I may have spoken to soon... it appears to be displaying on the page now but for some reason will only display one result and not all of them :S
mnakalay replied on at Permalink Reply
mnakalay
that's because in your block controller you are using VetSingleList which only gets one result. You should be using VetPageList to have them all.
In your block's controller, at the top you have
use \Concrete\Package\Vets\Src\VetSingleList;

change it to
use \Concrete\Package\Vets\Src\VetPageList;

Then lower down, in the view function, you have
$vetList = new VetSingleList();

Change that to
$vetList = new VetPageList();