@@ -1,6 +1,7 @@ |
{maketoc}
|
The Bitweaver Framework, consisting of Liberty and Kernel, offers you a lot of functionality. Here we'll try to show how you can make use of that.
|
|
+!Your Own Package |
!Business Objects a la Liberty
|
!!Which base class?
|
If you want to create your own [http://en.wikipedia.org/wiki/Business_object_(computer_science)|Business Object], you will probably use LibertyAttachable as base class, as it offers most functionality. Use LibertyContent or LibertyBase when you know what you are doing.
|
|
|
@@ -20,25 +21,25 @@ |
|
class BitResource extends LibertyAttachable {
|
|
- /**
|
- * During initialisation, be sure to call our base constructors
|
- **/
|
- function BitResource( $pContentId=NULL ) {
|
- LibertyAttachable::LibertyAttachable();
|
+ /** |
+ * During initialisation, be sure to call our base constructors |
+ **/ |
+ function BitResource( $pContentId=NULL ) { |
+ LibertyAttachable::LibertyAttachable(); |
|
- $this->mContentId = $pContentId;
|
- $this->mContentTypeGuid = BITRESOURCE_CONTENT_TYPE_GUID;
|
+ $this->mContentId = $pContentId; |
+ $this->mContentTypeGuid = BITRESOURCE_CONTENT_TYPE_GUID; |
|
- $parms = array(
|
- 'content_type_guid' => BITRESOURCE_CONTENT_TYPE_GUID,
|
- 'content_description' => 'Managed Resource',
|
- 'handler_class' => 'BitResource',
|
- 'handler_package' => 'mypackage',
|
- 'handler_file' => 'BitResource.php',
|
- 'maintainer_url' => 'mailto:guess@who.com'
|
- );
|
- $this->registerContentType( BITRESOURCE_CONTENT_TYPE_GUID, $parms ); // register class with Bitweaver
|
- }
|
+ $parms = array( |
+ 'content_type_guid' => BITRESOURCE_CONTENT_TYPE_GUID, |
+ 'content_description' => 'Managed Resource', |
+ 'handler_class' => 'BitResource', |
+ 'handler_package' => 'mypackage', |
+ 'handler_file' => 'BitResource.php', |
+ 'maintainer_url' => 'mailto:guess@who.com' |
+ ); |
+ $this->registerContentType( BITRESOURCE_CONTENT_TYPE_GUID, $parms ); // register class with Bitweaver |
+ } |
|
}
|
?>
|
|
|
@@ -68,9 +69,8 @@ |
!!LibertyContent
|
LibertyContent is the base for objects to be treated by Liberty. They come with these features:
|
*their title and text content is subject to the full text seach
|
-
|
!!LibertyBase
|
-!Sorted Lists
|
+!!Lists, sorted and filtered |
Now let us create a list of resources. Hopefully you already have something in your database so get something to see. As a first, insert this data with your favourite client, or even better with the data pump described below.
|
|
Now we will write some code that loads your data from the database. It goes to _index.php_ in your package directory.
|
|
|
@@ -99,13 +99,15 @@ |
$bindVars[] = '%' . strtoupper( $find ). '%';
|
}
|
|
- $query = "SELECT lc.`content_id`, lc.`title`, lc.`data` $selectSql
|
- FROM `".BIT_DB_PREFIX."liberty_content` lc $joinSql
|
- WHERE lc.`content_type_guid` = ? $whereSql
|
- ORDER BY ".$this->mDb->convert_sortmode( $sort_mode );
|
- $query_cant = "select count(*)
|
- FROM `".BIT_DB_PREFIX."eventcal_events` ts INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON( lc.`content_id` = ts.`content_id` ) $joinSql
|
- WHERE lc.`content_type_guid` = ? $whereSql";
|
+ $query = "SELECT lc.`content_id`, lc.`title`, lc.`data` $selectSql |
+ FROM `".BIT_DB_PREFIX."liberty_content` lc $joinSql |
+ WHERE lc.`content_type_guid` = ? $whereSql |
+ ORDER BY ".$this->mDb->convert_sortmode( $sort_mode ); |
+ $query_cant = "select count(*) |
+ FROM `".BIT_DB_PREFIX."eventcal_events` ts |
+ INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON( lc.`content_id` = ts.`content_id` ) |
+ $joinSql |
+ WHERE lc.`content_type_guid` = ? $whereSql"; |
|
$result = $this->mDb->query( $query, $bindVars, $max_records, $offset );
|
$ret = array();
|
|
|
@@ -123,10 +125,37 @@ |
|
*$gBitSmarty->assign_by_ref(...)
|
*$gBitSystem->display(...)
|
-!Detail Views
|
-Up to now, the answer is to look at the ((SamplePackage)) and guess.
|
-!Feedback and Confirmation
|
+ |
+!Make something visible: The UI |
+Probably you cannot wait to display somethind on the screen. Up to now we had concentrated on your data objects - the model. Bitweaver works with the MVC pattern. Find out more about this pattern in ((Model View Controller - MVC)), but now we make use of the model, create a simple controller and focus on the view. |
+ |
+{attachment id=268 float=right padding=20px} Have a look at this picture. It should give you a rough idea of what part of a bitweaver page you will be working on. |
+ |
+In most cases you write ordinary module code that goes into the main area in the middle. Then you can place any HTML/JavaScript/whatever code in your templates but surround it with the tag <div class="bitmain">, which will look like this: |
+{code} |
+<div class="bitmain"> |
+ <!-- your HTML here --> |
+</dov> |
+{/code} |
+Or you might be creating a module, in which case it is displayed either in the left or right column. In that case surreund your HTML with <div class="bitmodule"> as shown: |
+{code} |
+<div class="bitmodule"> |
+ <!-- your HTML here --> |
+</dov> |
+{/code} |
+Don't use tables to control the position as Bitweaver already takes care for the layout (and that can be changed in the admin menu). If you cannot believe it, read ((Table_vs_Div)). |
+ |
+Of course within the <div> element you can use tables to organise your information. |
+ |
+!!List Views |
+*The Controller |
+*The Template (View) |
+!!Detail Views |
+*The Controller |
+*The Template (View) |
+!!Feedback and Confirmation |
Up to now, the answer is to look at the ((SamplePackage)) and guess.
|
+errors, warnings, message text and confirmation dialogs |
*gBitSystem->setBrowserTitle()
|
*gBitSystem->confirmDialog()
|
!Authorisation Required
|
|
|
@@ -209,7 +238,15 @@ |
|
!!Data Format
|
!!!National language characters
|
-What encoding should be used for the PHP file? How shall national language characters (at worst the complete unicode character set) be escaped?
|
+^Short answer: Make sure all your PHP and TPL files are encoded in UTF-8.^ |
+ |
+Apache, PHP and Bitweaver operate on byte streams. Character sequences are just arrays of bytes. So you need not care what character encoding your national special characters are in - as long as the data is supplied by browsers. |
+ |
+Per default Bitweaver tells the web browser that UTF-8 is used. Therefore any data presented to the browser is assumed to be UTF-8 (even if it is not which results in garbage) and the browser will send user input encoded in UTF-8. That solves the problem almost completely. |
+ |
+There are two items which you will have to look at: Your PHP source and template files. Again, PHP does not assume any encoding on the files, they are just loaded as byte arrays. The PHP code in these files should not contain anything beyond ASCII, but any characters within string literals can. And this data goes untouched through the whole system until it has to be displayed on the screen. As mentioned earlier, the browser will assume all data to be in UTF-8. So you can see garbabe being displayed unless you change the encoding of those characters. |
+ |
+__Note:__ I've seen troubles with trimming down text with special chars. The common example is when article gets automaticly cut after the set number of letters, and the rest is placed to the "read more" part. It says letters, but it actually uses bytes to count. It takes 2 bites to encode most non-Latin1 chars, so after trimming sometimes the last letter is presented with only one bite of 2 necessary, and shows in browser as garbage. So until this is fixed somehow, avoid trimming texts by your php files and templates if you use special chars. |
|
!!!Timestamps
|
Bitweaver is said to use UTC times within the database. What times are used on timestamps in the installer?
|
|
|