0

I'm creating a new package for Concrete 5 (5.4.0+). Inserting a new block works perfectly. But when I edit an existing block, it tries to INSERT again when I click 'save', instead of UPDATE.

The two fields on the database that affect this are bID and eID. Both are non-auto-incrementing INT(10) default none NOT NULL.

The values are passed in an associative array $args in the controller and I'm calling the parent save method with Parent::save($args);

Any help/input would be appreciated. PS: I have looked over this on the net and the C5 forums did turn up some stuff which I tried, mostly relating to the database fields, but I still get the above error. I don't want to overwrite the ADODB save() method if possible.

--- EDIT ---

Perhaps I'm looking at this all wrong. Let me say what I'm trying to achieve. I need the eID to remain 37 (for example) across multiple edits of the block. The bID can increment away AFAIC.

How do I get the eID to remain 37 on edit, but increment by 1 on creation of a new instance? Make sense?

A second table references the eID field, and edited instances of an entry on this table must have the same eID unless a new instance is created. Sry - clear as mud I know.

Jongosi
  • 2,305
  • 1
  • 28
  • 31

2 Answers2

0

Are you saying you get a new instance of the block appearing on your page, rather than a new version of the existing one? I don't think the problem is with there being a new record inserted in your table, since new records are normally created when you edit a block. C5 keeps the older version of the block.

The custom blocks I've done have never required a call to the parent save method. You just need an edit form that collects the data and designates which database field it corresponds to, and the parent controller knows what to do with it when the form is submitted.

For example, if you have a text field in your block table called "firstname" that you are updating, you would add a line to your edit.php file like this:

<?php echo $form->text('firstname', $firstname, array('style' => 'width: 320px'));?>

My block editors contain little else than this, other than html/CSS stuff to add labels and make the form look better. The $form object takes care of everything else.

One thing that really helped me understand blocks and block controllers was to download and install the "designer content" add-on. It's free. You can use it to build some custom blocks, then look at the code it generates to perform various functions.

  • Yeah, good point. I know that C5 creates new block instances on `save`, but I need the eID field to remain consistent from one edit to another, unless a new instance is created, in which case, eID should increment by 1, make sense? You have a good point though - perhaps I'm looking at this from the wrong perspective :( – Jongosi Sep 10 '12 at 16:27
  • Are you using it to identify each instance of your block type? If so, then I think you're probably trying to go for a little more granular control than you really need to, in most situations. – landollweb Sep 10 '12 at 18:27
  • So I have 2 tables, `btBirthdayParty` and `btBirthdayPartyGoers`. The `eID` field in question is on `btBirthdayParty`. People signing up to attend go into the `btBirthdayPartyGoers` table, with an eID field linking them to the party they are attending. If I edit the `btBirthdayParty` block instance, I can't have the eID increment on save coz we'll lose the association with our party goers. However, when I create a new party, I need a new eID so that everyone is not going to the same party... – Jongosi Sep 11 '12 at 06:12
  • I guess I could just put a field on the form to ask whether this is a new instance or edit of an instance? Nasty but effective. – Jongosi Sep 11 '12 at 08:08
  • 1
    Ah okay, you have multiple tables. I would suggest taking a look at one of the core blocks that handles referential integrity between multiple tables and see what approach is used there. The form block is one (/concrete/blocks/form/*.*). – landollweb Sep 11 '12 at 21:29
0

So I looked into the existing packages to duplicate this funcitonality and my question has evolved into this: PHP Concrete 5 Pass Variables to Add.php

Follow the rabbit ;)

Community
  • 1
  • 1
Jongosi
  • 2,305
  • 1
  • 28
  • 31