PX - Plugins


Write plugins to extend functionality of the pxObject.

Here are some rules to keep in mind if you want to write a plugin:

  • Plugin Functions are implemented by classes that extend px_method.
  • Plugin class names must start with "px_method_", followed by the function name.
  • Plugin classes must implement a method named "exec".
  • If the exec method returns no value, $this will automatically be returned.

Here's the code that implements a plugin function called "tag".

class px_method_tag extends px_method
	public function exec ($ar) {
		$doc = $this->px()->doc;
		$node = $doc->createElement($ar[0], isSet($ar[1])?$ar[1]:"");
		$this->nodes = new px_item_list($node);
		return new px_nodes($this->px(), $node);

Call the tag plugin just as you would any other px function:

	$doc = px("<div><b>Hello!</b></div>");
	$new = $doc->tag("pre", "Hello, World!")->appendTo("//div");
	echo $doc->html();
  <pre>Hello, World!</pre>


The tag plugin is not a part of the pxtreme project. In fact, there are no plugins specifically associated with this project. However, it's easy enough to make a tag plugin for yourself - simply copy the code into a file called tag.php.

You can make the tag plugin available by including it via one of the PHP include methods.

	// for example...
	include_once ("px.017.php");
	include_once ("plugin/tag.php");
	echo px("<div/>")->tag("b", "Hello, World!")->appendTo("/div")->html();