Code examples in PHP5

Create a module
class Home extends BaseModule 
{
      public function __construct()
      {}

      public function CreatePage() 
      {
            $this->defaultXmlnukeDocument = new XmlnukeDocument("Title", "Abstract");
            ...
            return $this->defaultXmlnukeDocument;
      }
}

Create a module which requires authentication
class Home extends BaseModule 
{
      public function getAccessLevel()
      {
          return AccessLevel::OnlyRole;
      }

      public function getRole()
      {
          return new array("DIRECTOR", "MANAGER");
      }
}

Module with conditional cache
class Home extends BaseModule 
{
      public function useCache()
      {
            if ($this->_action != "")
            {
                  return false;
            }
            else
            {
                  return true;
            }
      }
}

Create a form
// Create a XML Block
$block = new XmlBlockCollection("Title", BlockPosition::Center);
$this->defaultDocument->addXmlnukeObject($block);

// Create a Form
$form = new XmlFormCollection(
    $this->_context, "module:demo.home", "Title");
$form->setJsValidate(true);
$form->setDecimalSeparator('.');
$form->setDateFormat(DATEFORMAT::MDY);
$block->addXmlnukeObject($form);

Create a text box
// Simple Text Box
$form->addXmlnukeObject(
	new XmlnukeInputText("Caption", "name", "", 10)‏
);

// Hidden Field
$form->addXmlnukeObject(
	new XmlnukeInputHidden("name", "value", 10);
);

// Required field
$text = new XmlnukeInputText("Caption", "name", "", 10);
$text->setRequired(true);

// Numeric field
$text = new XmlnukeInputText("Caption", "name", "", 10);
$text->setDataType(INPUTTYPE::NUMBER);
$form->addXmlnukeObject($text);

// Read-only field
$text = new XmlnukeInputText("Caption", "name", "", 10);
$text->setReadOnly(true);
$form->addXmlnukeObject($text);

// AutoSuggest Field
$text = new XmlnukeInputText("Caption", "name", "", 10);
$text->setAutosuggest($this->_context, "module:demo.ajax.country", "q");

Access relational databases
// Connect to the database
$db = new DBDataSet("conection", $this->_context);

// Get the data through an iterator
$it = $db->getIterator(
    "select * from tabela where campo = [[filter]]", 
    array("filter"=>"john")
);

// Walk through all records
while ($it->hasNext())‏
{
	$sr = $it->moveNext();
	Debug::PrintValue($sr->getField("field"));
}

Connect to an alternative data source
// Connect to an array
$array = new array("01"=>"January", "02"=>"February", "03"=>"March");
$db = new ArrayDataSet($array);

// Get the data through an interator from the Array
$it = $db->getIterator();

// Walk through all records
while ($it->hasNext())‏
{
	$sr = $it->moveNext();
	Debug::PrintValue($sr->getField("value"));
}

Fill a table
// Fill a XML EditList from an Iterator
$editlist = new XmlEditList($this->_context, "Title", "");
$editlist->setReadOnly(true);
$editlist->setDataSource($iterator);

/*
Note:
The iterator is a normal object inside XMLNuke. 
Most of components uses an Iterator as a Data Source.

Some data sources existing on XMLNuke:
DbDataSet, ArrayDataSet, TextFileDataSet, XmlDataSet, ...
*/

Create a CRUD (Create, Retrieve, Update and Delete)
// Basic Manage Table
$fld = ProcessPageFields::FactoryMinimal("field1", "label1", 10, $visible, $required);
$fld->key = true;
$fields->addProcessPageField($f);

$fld = ProcessPageFields::FactoryMinimal("field2", "label2", 10, $visible, $required);
$fld->dataType = INPUTTYPE::DATETIME;
$fields->addProcessPageField($f);

$process = new ProcessPageStateDB($this->_context, $fields, "Editing", "module:demo.teste", 
	null, "table_name", "connection");
$block->addXmlnukeObject($process);

Processing button events
// Create a event button inside a form.
$button = new XmlInputButtons();
$button->addClickEvent("Fire event", "Name");
$form->addXmlnukeObject($button);

// You have enable event processing inside module
$this->processEvent();

// Handle the event
public function Name_Event()
{
	...
}

Fill a class automatically
// Create a Model Class
class PersonModel
{
	protected _id; 
	public setId($val) ...; 
	public getId()..;

	protected _name; 
	public setName($val) ...; 
	public getName() ...;
}

// Call the module
http://localhost/xmlnuke.php?module=demo.teste&id=1&nome=jose

// Fill the class automatically
$person = new PersonModel();
$this->bindParameteres($person);

Other built-in and ready-to-use objects in XMLNuke:

  • XmlnukeCalendar
  • XmlnukeFlash
  • XmlnukeImage
  • XmlnukePoll
  • XmlnukeTabView
  • XmlnukeTreeView
  • XmlDualList
  • XmlChart
  • XmlContainer
  • etc...

Read in this page :



SourceForge Logo