Custom Block not Installing - no database table

Permalink 1 user found helpful
I am developing a very simple Block (e.g. 'Hello World' for all instances). It does not need a database table.

I used the "basic_test" Block and stripped-out the db.xml and the btTable reference in the controller.php

Whenever I click "Install", I receive a message that it has installed. However, it does not move to the installed Blocks list (stays on the right-hand-side).

Is there any way of installing a Block that does not need to use a database table?

garrycl
 
digirunt replied on at Permalink Best Answer Reply
digirunt
Hello

db.xml is a minimum requirement for a block and requires at least two fields, one called bID for storing core info about where the block is etc and the other is block specific so if not needed can just be a dummy field.

More here
http://www.concrete5.org/documentation/developers/blocks/directory-...

and

http://www.concrete5.org/community/forums/block_requests/block_with...
garrycl replied on at Permalink Reply
garrycl
Thanks digi :)

Unfortunately, I was reading this page:
http://www.concrete5.org/documentation/developers/blocks/understand...

Which said the db.xml was only required for Blocks using the database.

All go now, so much creative developing tonight!

Thanks again.
ScottC replied on at Permalink Reply
ScottC
the reason why it needs a dummy field is because the $db->replace will die unless there is something other than a id field :)

i find in the rare instances where you have a block that doesn't really do anything(except for marking areas for inclusion where another block doesn't exist or something like that) that it is fine to just include a name field.

I wrote one that had just a bID and came across the dying on the replace error since all the fields or properties of the block were held in a hasMany relation to the block's bID, which is really neat and all but it still needs that other field.

Hope that clears it up for others.
carlos123 replied on at Permalink Reply
I am curious, if you all are still following this thread, if there is an easier way to create a block with no table use (well...than creating a dummy table at least) for purposes of using a block's view.php file to manipulate certain values into the HTML of that file?

For example I have some HTML code where I want to replace the value of a certain HTML input with the value of the page URL on which that code is found. This HTML goes into just about every page of the site. And I will want replace that input field value with the URL of each page.

But I can't run PHP inside the normal HTML or Content blocks. So I thought creating a block just so as to be able to use the view.php file to do that in would be the way to go.

Is there an easier way?

Anybody?

Carlos
12345j replied on at Permalink Reply
12345j
hey,
theres a much easier way to do this by using events. Create a file at root/config/site_events.php and put this code
Events::extend('on_page_output', 'ModifyHtml', 'modify', 'models/modify_html');
and then create a file at root/models/modify_html with this in it
Class ModifyHtml{
    public function modify($content){
      //now modify the $content variable which is the html of the entire page with a regex or replace
                return $content;
   }
}

which should be a more elegant solution because it will work automatically on all pages.
carlos123 replied on at Permalink Reply
Hmm...what if I want to have the code show up on only certain pages 12345j?

For example on the site I am finishing up I have 25 photo pages.
Each of those pages will have Paypal shopping cart buttons. The rest of the pages on the site don't have that shopping stuff.

I've created a global scrapbook block and have placed it only on the 25 photo pages. All well and good.

But within that block I discovered that I need to pass the URL of the page sending Paypal the information from the form of that block. Thus my need to replace one of the variables passed to Paypal with the name of the page it came from.

Will your event, as you describe it, show up on all pages of the site or is there a way to create an event to show up only on those pages which I designate?

Carlos
12345j replied on at Permalink Reply
12345j
hmm. thats interesting. Little more hacking, but still doable. copy root/concrete/libraries/view.php to root/view.php and change this line
$ret = Events::fire('on_page_output', $pageContent);
to this
$ret = Events::fire('on_page_output', $pageContent,$this);
and then change the modify function to be
public function modify($content,$page){
    //$page is the page object, so get stuff from it- like checking the parent, page type, id, and other stuff, and if it is a photo page modify, otherwise, just pass through.
    return $content
}
carlos123 replied on at Permalink Reply
Hmmm...I'll have to play around with what you suggest 12345j but for now...since I have a working block already that uses a dummy table, I think I'll stick to that method.

Thing is that my Photo Pages (which have the Paypal shopping cart form on them with the variable that must be modified with the page's URL) don't really have anything unique so as to be able to identify them as Photo Pages. Well...they do have an image but then so do other pages that are not Photo Pages per se.

So it would take a bit of hacking around and fiddling around to implement what you suggest.

I am under a tight deadline and must finish this off this weekend so for now, I'll stick to what I know. Block creation.

Thanks anyway 12345j. Your input is much appreciated.

Maybe someone else will be able use what you have shared.

Carlos