{maketoc}
|
|
-!Displaying your Own Table in bitweaver
|
|
-!!Introduction
|
+!Introduction |
This is a BASIC tutorial that will show you how to make a quick package that loops through a table and displays its data. I wrote this because I am starting from the VERY beginning here in bitweaver, and want to make tutorials as I go to help new opensource developers who are joining the project and need a booster seat to sit at the table! I hope it is useful to you!
|
Thanks for your help Spiderr
|
|
-!!1) Create a New Package
|
+ |
+!!1) Create a New bitweaverPackage |
* Go to the root of your bitweaver installation and make a directory:
|
-{CODE()}$ mkdir newPackage
|
+{CODE source='php' num='off'} |
+$ mkdir newPackage |
$ mkdir newPackage/modules
|
$ mkdir newPackage/templates{CODE}
|
!!2) Create your table
|
-* Using PostgreSQL, and a neat utility like [http://www.pgadmin.org/pgadmin3/index.php|pgAdmin3] create a database called ''test_table'', and add two colums: ''nameid'', and ''memo'', or use the sql below
|
-{CODE()}CREATE TABLE test_table
|
+* In your bitweaver database, create a table called ''test_table'', and add two colums: ''test_table_id'', and ''memo'', or use the sql below. Later we shall see how such tables can be created during plugin installation. |
+{CODE source='php' num='off'}-- Note: This first CREATE statement works for postgreSQL |
+CREATE TABLE test_table |
(
|
- nameid int2 NOT NULL,
|
- memo text[],
|
- CONSTRAINT test_table_pkey PRIMARY KEY (nameid)
|
-) WITHOUT OIDS;{CODE}
|
+ test_table_id int NOT NULL, |
+ memo text[] |
+) WITHOUT OIDS; |
+-- |
+-- This CREATE TABLE statement works for MySQL and MSSQL |
+CREATE TABLE test_table |
+( |
+ test_table_id int NOT NULL, |
+ memo text |
+) |
+{CODE} |
+ |
+Insert several rows into the table. |
+{CODE source='php' num='off'}--These INSERT statements work for postgreSQL, MySQL and MSSQL |
+INSERT INTO test_table (test_table_id, memo) VALUES (1, 'The first memo' ); |
+INSERT INTO test_table (test_table_id, memo) VALUES (2, 'The second memo' ); |
+INSERT INTO test_table (test_table_id, memo) VALUES (3, 'The third memo' );{CODE} |
+ |
!!3) Create your PHP file
|
* Go to __newPackage/__ and create a file called ''index.php''
|
* Add the following lines
|
-{CODE()}<?php
|
- require_once('../tiki_setup_inc.php'); //initialized the entire system!
|
- $result = $gTikiSystem->query("SELECT * FROM test_table");
|
- $smarty->assign('test_table', $result->GetArray());
|
+{CODE source='php' num='off'}<?php |
+ require_once('../bit_setup_inc.php'); //initialized the entire system! |
+ $result = $gBitDb->query("SELECT * FROM test_table"); |
+ $gBitSmarty->assign('test_table', $result->GetArray()); |
+ $gBitSystem->display( NEWPACKAGE_PKG_PATH . '/templates/newPackage.tpl', 'New Package Page' ); |
+?>{CODE} |
+!!4) Create your package's bit_setup_inc file |
+* Go to __newPackage/__ and create a file called ''bit_setup_inc.php'' |
+* Add the following lines: |
+{CODE source='php' num='off'}<?php |
+global $gBitSystem; |
+$gBitSystem->registerPackage( 'newPackage', dirname( __FILE__ ).'/' ); |
+if( $gBitSystem->isPackageActive( 'newPackage' ) ) { |
+ // ... maybe do some initialization stuff if your package is turned on |
+} |
+?>{CODE} |
+* For Bitweaver 2.0 you will want the file to look like this: |
+{CODE source='php' num='off'}<?php |
+global $gBitSystem; |
+$registerHash = array( |
+ 'package_name' => 'newPackage', |
+ 'package_path' => dirname( __FILE__ ).'/', |
+ 'homeable' => TRUE, |
+); |
+$gBitSystem->registerPackage( $registerHash ); |
|
- $gTikiSystem->display( 'tikipackage:newPackage/newPackage.tpl' );
|
+if( $gBitSystem->isPackageActive( 'newPackage' ) ) { |
+ // ... maybe do some initialization stuff if your package is turned on |
+} |
?>{CODE}
|
-!!4) Create your Smarty TPL file
|
+!!5) Create your Smarty TPL file |
* Now go to __newPackage/templates__ and create a file using pico, or whatever you use, called ''newPackage.tpl''
|
* Add these lines:
|
-{CODE()}<table>
|
+{CODE source='php' num='off'}<table> |
{section name=colnum loop=$test_table}
|
<tr>
|
- <td>{$test_table[colnum].nameid}</td>
|
+ <td>{$test_table[colnum].test_table_id}</td> |
<td>{$test_table[colnum].memo}</td>
|
</tr>
|
{/section}
|
</table>{CODE}
|
+Bitweaver uses the Smarty template engine, enriched with some custom functions. Read more about that on ((Smarty Functions)). |
+ |
+!!6) Activate your new package |
+*Click Administration -> Kernel -> Packages |
+*Scroll down to find "newPackage" (the list is alphabetical) |
+*Check the box to enable the package |
+*Go all the way to the bottom and click the "Activate" button |
+ |
!Voila!
|
Go to __http://yourbitweaverURL/newPackage/__ and your table should be displayed!
|
-!!5) Now, create a Module
|
-* Create a module (a little box that you can display in the left or right columns) with a pointer to your awesome new package.
|
-{CODE()}$ mkdir newPackage/modules{CODE}
|
-* and create a file using pico, or whatever you use, called ''mod_newPackage.tpl''.
|
-* The file name must be formated like this so the tikisystem can include it in the __Administration / Modules__ dropdown list.
|
+ |
+!!7a) Now, create a Module |
+* To create a module (a little box that you can display in the left or right columns) with a pointer to your awesome new package, we will use the modules directory you created in step 1 |
+* Create a file using pico, or whatever text editor you use, called ''mod_newPackage.tpl''. |
+* The file name must be formated like this so bitweaver can include it in the __Administration / Modules__ dropdown list. |
* Add these lines to the file:
|
-{CODE()}<table>
|
+{CODE source='php' num='off'}<table> |
<tr>
|
- <td class="boxtitle"><b>Planning</b><br></td>
|
+ <td class="boxtitle"><b>Planning</b> |
+</td> |
</tr>
|
<tr>
|
- <td><a href="{$gTikiLoc.newPackage_PKG_URL/index.php">
|
- {tikicon ipackage=newPackage iname=iconname iexplain="this is a cool icon"}My New Package</a></td>
|
+ <td><a href="{$smarty.const.NEWPACKAGE_PKG_URL}index.php"> |
+ { biticon ipackage=newPackage iname=iconname iexplain="this is a cool icon"}My New Package</a></td> |
</tr>
|
</table>{CODE}
|
-(:exclaim:) __$gTikiLoc.whatever_PKG_URL__ is a pointer to a folder called whatever in the root...
|
-to use icons check out our cool new icon system called ((function_tikicon|tikicon))
|
+(:exclaim:) __$smart.const.whatever_PKG_URL__ is a pointer to a folder called whatever in the root... |
+to use icons check out our cool new icon system called ((function_biticon|biticon)) |
|
-!!6)List of available constants in bitweaver
|
+!!7b) Add menu entries |
+Maybe you chose your package be no module. Maybe you have additional functionality that shall plugin into Bitweaver's menu bar. This is a two step procedure. |
+ |
+First create your templates/menu_newPackage.tpl file with the menu items you want to add. |
+{CODE source='php' num='off'} |
+<ul> |
+ <li><a class="item" href="{$smarty.const.NEWPACKAGE_PKG_URL}index.php">{tr}New Package Home{/tr}</a></li> |
+ <li><a class="item" href="{$smarty.const.NEWPACKAGE_PKG_URL}view1.php">{tr}View Something{/tr}</a></li> |
+ <li><a class="item" href="{$smarty.const.NEWPACKAGE_PKG_URL}view2.php">{tr}View something else{/tr}</a></li> |
+</ul> |
+{CODE} |
+ |
+Then register the menu in bit_setup_inc.php. |
+{CODE source='php' num='off'} |
+if( $gBitSystem->isPackageActive( 'newPackage' ) ) { |
+ $menuHash = array( |
+ 'package_name' => NEWPACKAGE_PKG_NAME, |
+ 'index_url' => NEWPACKAGE_PKG_URL.'index.php', |
+ 'menu_template' => 'bitpackage:eventcal/menu_newPackage.tpl', |
+ ); |
+ $gBitSystem->registerAppMenu( $menuHash ); |
+} |
+{CODE} |
+To read more about menus, read ((Adding YOUR OWN dropdown menu to the Nav bar!)). |
+ |
+!!8) List of available constants in bitweaver |
|
-=automagically generated constants for each package of the form=-
|
<PACKAGE>_PKG_PATH --> example: WIKI_PKG_PATH
|