codeigniter-xhtml-library by Serafim Junior Dos Santos Fagundes Cyb3r Network

Version 1.2.1

MIT License

Copyright (c) 2010 Serafim Junior Dos Santos Fagundes Cyb3r Network


codeigniter-xhtml-library is a CodeIgniter library for Strict XHTML 1.0 document
generation. The goal of the library is to remove the burden (although it ain't
really one) of switching between HTML and PHP and to give a 100% PHP focus to
the coder. This library serves also as an experiment of maintenance for tag
generation with PHP.


In the controller...

Load the library.

	$this->load->library( 'xhtml' );

You can pass an array as the second parameter for the language, encoding and
XHTML version to the resulting document:
Value of key 'version' is one of these:

- 'xhtml11'
- 'xhtml1-strict'
- 'xhtml1-trans'
- 'html4-trans'

	# Displaying default values
	$params = array( 'encoding' => 'utf-8', 'short_lang' => 'en', 'version' => 'xhtml1-strict' );

	$this->load->library( 'xhtml', $params );

In the view...

Create the XHTML tags in the views.

	# Create <head>
	$head = $this->xhtml->head();

		# Create tag <title>
		$title = $this->xhtml->title( 'My first document' );

	# Append <title>
	$head->append( $title );

		$charset = $this->config->item( 'charset' );

		$attrs = array();

		$attrs['Content-Type'] = "text/html;charset=".$charset;

		# Create tag <meta> with attributes
		$meta = $this->xhtml->meta( $attrs );


		# Create tag <h1>
		$h1 = $this->xhtml->h1( 'Hello World!' );

		# Set id
		$h1->id( 'myHeader' );

		# Attributes for <h1> tag
		$h1->attr( 'style', 'color:red;' );
	# Append <h1>
	$body->append( $h1 );
		# Create tag <p> with attributes
		$p = $this->xhtml->p( 'Lorem ipsum...', $attrs );
		# Set class
		$p->klass( 'lorem' );

	$body->append( $p );

	# Add $head and $body to doc
	$doc = $this->xhtml->doc( $head, $body );

	# Generate and echo XHTML document