BIF3
[ class tree: BIF3 ] [ index: BIF3 ] [ all elements ]
Prev Next
Creating WidgetsBasic Constructions

BifWidget is the basic object in BIF framework. All widgets 'extends BifWidget' or a subclass.

Lets see a simple example, create Widgets/HelloWold.php
class HelloWorld extends BifWidget {
  function HelloWorld ($attrs = array()) {
    $this->BifWidget($attrs);
  }
}

Now we need to add a skin file. create Skins/Default/helloworld.tpl
Hello World!

Template skin files shuld be lower-case.

Using widgets

Now we have created a widget, we need to use it. In your application directory create hello.php
include "bifConfig.inc.php";
$test =& new HelloWord;
print $test->draw();

Let's get this simpler!. In your application directory create hello2.php
include "bifConfig.inc.php";
$test =& render_file("Contents/hello2.bif");
print $test->draw();

And now, create directory Contents and Contents/hello2.bif
<HelloWorld />

Actually a bad HTML will be generated, change Contents/hello2.bif:
<BifRoot>
<HelloWorld />
</BifRoot>

Widgets with parameters

This is boring! let's do something more exiting!, like Contents/hello3.bif:
<BifRoot>
<HelloWorld myname="Nico" />
</BifRoot>

We just added attribute 'myname' to HelloWorld, then we need to do de folowing changes to Widgets/HelloWorld.php:
class HelloWorld extends BifWidget {
        function HelloWorld ($attrs = array()) {
          $this->BifWidget($attrs);
        }
        function innerDraw() {
          $this->RawFields=array('MYNAME');
        }}

Watch the uppercase: MYNAME, not myname or MyName.

And we must change the skin file.Modify Skins/Default/helloworld.tpl
Hello, {MYNAME}!

See changes in your browser, http://app.com/index.php,
Hello world example

Hello, Nico!

and it's an valid HTML, if you mantanined all files.

Conclusion:

Templates use gives us representation is separated from logic. Making the application more maintainable. Plus, with BIF we have "legos" to play with, called BifWidgets (or Widgets) within XML-based .bif files. Making it more easier!

What next?

Creating more widgets.

Prev   Next
Creating More Widgets Instalación de BIF (Spanish)

Documentation generated on Wed, 10 Nov 2004 19:41:18 -0300 by phpDocumentor 1.2.3