Package with a table
Permalink
Hi. I want a package, with a couple of blocks, but all these blocks must share the same tables.
I can build a package with some blocks and build those tables in only one block and access them via the others. But this is logically wrong.
I can also build the tables in each block, which means data redundancy.
What I'm doing right now is that I have only one block, and separate display modes are included in different pages. The User chooses what kind of block he needs, and the associated page is included through a switch case. This isn't what I want. See, it's hard setting permissions and what ever...
My Package is News. in news I need blocks such as: Admin, Display, Statistics, Archive...
Any idea on how I can build a package with a table. And all blocks in that package use the tables the package provides?
I can build a package with some blocks and build those tables in only one block and access them via the others. But this is logically wrong.
I can also build the tables in each block, which means data redundancy.
What I'm doing right now is that I have only one block, and separate display modes are included in different pages. The User chooses what kind of block he needs, and the associated page is included through a switch case. This isn't what I want. See, it's hard setting permissions and what ever...
My Package is News. in news I need blocks such as: Admin, Display, Statistics, Archive...
Any idea on how I can build a package with a table. And all blocks in that package use the tables the package provides?
Hi. I'm not sure if I understand you: You can define tables in your package's db.xml. Access these table from within your blocks. Or write an interface to access it from a single page under the dashboard. Or both. Is this what you're asking for?
thanx. You got it. Is this what you're saying:
I make a package named news. inside my package I make a db.xml, create my tables here and in the package controller I tell it to build the db.xml table table1. then I make a folder blocks, inside it block1 block2 block3.
and these blocks will have access to the table1?
package
- news - blocks
- block1
- block2
- db.xml
- icon.png
- CHANGELOG
Will this work?
I make a package named news. inside my package I make a db.xml, create my tables here and in the package controller I tell it to build the db.xml table table1. then I make a folder blocks, inside it block1 block2 block3.
and these blocks will have access to the table1?
package
- news - blocks
- block1
- block2
- db.xml
- icon.png
- CHANGELOG
Will this work?
You just write your tables to db.xml to create them. No need to do this in controller.php. But you have to give your users the chance to put content into the table!
The blocks have access to the table - everyone in c5 has acces to all tables: you have to do appropriate sql queries in your block's controller and/or in the add/edit.php.
C5 just creates your tables on installing the package following the db.xml. It calls your block's controller.php and add/edit.php if users select your block. It saves the content of your add/edit.php html form in add.php and edit.php to the block's tables (if fields have the same name like the table colums). It reads these fields on displaying your blocks and pass it to view.php. That's all (but it's already many). All the rest is your job!
There is a simple sample package made by c5 to show the basic code for packages. You find it here together with other information on packages:http://www.concrete5.org/help/building_with_concrete5/developers/pa...
The blocks have access to the table - everyone in c5 has acces to all tables: you have to do appropriate sql queries in your block's controller and/or in the add/edit.php.
C5 just creates your tables on installing the package following the db.xml. It calls your block's controller.php and add/edit.php if users select your block. It saves the content of your add/edit.php html form in add.php and edit.php to the block's tables (if fields have the same name like the table colums). It reads these fields on displaying your blocks and pass it to view.php. That's all (but it's already many). All the rest is your job!
There is a simple sample package made by c5 to show the basic code for packages. You find it here together with other information on packages:http://www.concrete5.org/help/building_with_concrete5/developers/pa...
Thanx. I did it yesterday, got a couple of errors and fixed it. I thought my blocks didnt have access to the tables but the error was because the blocks must have a table for them selves. Anyway I worked it out. Appreciate your help.