{maketoc}
|
-!!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 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
|
-* In your bitweaver database, create a table called ''test_table'', and add two colums: ''test_table_id'', 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 |
(
|
test_table_id int NOT NULL,
|
memo text[]
|
-) WITHOUT OIDS;{CODE}
|
+) 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()}INSERT INTO test_table (test_table_id, memo) VALUES (1, 'The first memo' );
|
+{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
|
+{CODE source='php' num='off'}<?php |
require_once('../bit_setup_inc.php'); //initialized the entire system!
|
- $result = $gBitSystem->query("SELECT * FROM test_table");
|
- $smarty->assign('test_table', $result->GetArray());
|
-
|
- $gBitSystem->display( 'bitpackage:newPackage/newPackage.tpl', 'New Package Page' );
|
+ $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 (the spaces in _ _FILE_ _ must be removed wiki thinks they should bold the FILE ! )
|
-{CODE()}<?php
|
+* Add the following lines: |
+{CODE source='php' num='off'}<?php |
global $gBitSystem;
|
-$gBitSystem->registerPackage( 'newPackage', dirname( _ _FILE_ _ ).'/' );
|
+$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 ); |
+ |
if( $gBitSystem->isPackageActive( 'newPackage' ) ) {
|
// ... maybe do some initialization stuff if your package is turned on
|
}
|