Best Practice question

Permalink
Just starting to work on a new package, it is going to have multiple blocks and multiple tables.

Each of the blocks will require access to all the tables.

Should I create the tables at the top package level or just in anyone of the blocks.

Does it matter?

I'll probably play about trying it all different ways but just wondered if there is a proper method for doing this?

Cheers
Al

engagingit
 
RadiantWeb replied on at Permalink Reply
RadiantWeb
for me it depends on where the data is mostly used.

But to me, it sounds like you would want to have your schema at the package level, and then lean on a model.

Block level tables are a quick and dirty way to bypass the need for a model if you are strictly working in a block context as C5 has all the data save and update methods built into the block model. But it's all local to the the block. You "can" access that data in any event, but you'll end up needing your own model anyway.

Chad
Mnkras replied on at Permalink Reply
Mnkras
personally i don't thing it really matters, i would think keep the tables that the blocks require in the blocks,

and the shared tables in the top level db.xml
engagingit replied on at Permalink Reply
engagingit
Thanks guys, sounds like the package level is the best way to go although I'll keep a couple of the tables which are specific to each block at the block level.
ScottC replied on at Permalink Reply
ScottC
I'd create the tables in db.xml in package root, the rest of them would be block specific views of data(db fields for templates, and the block's db.xml would store view specific data.

If you want to write to db tables from the block's save, you need to specify a save method in your block controller then call parent::save();, which calls the inherited classes save method which handles bID and things like that(and extracting db values from the post array($args);