Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!

Close
codeigniter-qview-library by Serafim Junior Dos Santos Fagundes Cyb3r Network

Version 1.0

MIT License

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

Needs codeigniter-xhtml-library.

--------------------------------------------------------------------------------

codeigniter-qview-library is a library for the CodeIgniter framework. Its a
companion library of codeigniter-xhtml-library for ease of XHTML templatization
and document creation.

Go see codeigniter-xhtml-library and codeigniter-qzones-library for more 
information.

--------------------------------------------------------------------------------


# Load the library in the controller.
# -----------------------------------
$this->load->library( 'qview' );


# Qview isn't used directly, you'll have to create a CI library that extends Qview
# --------------------------------------------------------------------------------

class My_qview extends Qview
{
	public function __construct( $params )
	{
		parent::__construct( $params );
	}
	
	
	# Overload the init method
	# ------------------------
	
	public function init()
	{
		parent::init( $this );	// Passing a reference of child to parent
					//  + The object reference will permit the
					//    the callbacks manipulation

	
		# Register the callbacks in the document parts
		# --------------------------------------------
		# Qview::_Reg( Qview::classConstant, 'triggerName', 'callbackMethod' );
		#
		# o classConstants
		#   - Qview::head : links the trigger name and callback to the
		#                   head part
		#   - Qview::body : links the trigger name and callback to the
		#                   head part
		#
		# o triggerName   : This will be the name we're going to call in
		#                   the view file
		#
		# o callbackMethod : This is the method used when triggered by
		#                    the triggerName. Passing $this in
		#                    parent::init() makes the callback usable.
		
		
		parent::_Reg( Qview::head, 'title', '_title' );
		
		
		# Register as many as you like
		# ------------------------------------------------------------
		#  + Just remember that for each Qview registration you'll need
		#    a distinct trigger name and a callback method declared in
		#    the current class.
		
		
		# Same for body
		# -------------
		
		parent::_Reg( Qview::body, 'content', '_content' );
	
	
		# Optional layout engine usage
		# ----------------------------
		# + Go see codeigniter-qzones-library for more information
		
		parent::_RegQVLLib( 'qzones', 'triggerName', $params );
	}
	
	
	# Declare the callback methods
	# ----------------------------
	# + I'll use the names declared in the Qview registry statements
	
	public function _title()
	{
	
		# In the method you can do anything. Just remeber to return a
		# codeigniter-xhtml-library (Xhtml) object
		# -----------------------------------------------------------
		
		$title = $this->oCI->xhtml->title( 'My document title' );
		
		# Qview loads the codeigniter instance and Xhtml library.
		# You can access it anytime with $this->oCI->xhtml
		
		return $title;
	}
	
	
	public function _content( $array_params )
	{
		# Method arguments can be used, just remember to pass them
		# as an array
		# --------------------------------------------------------
		
		$h1 = $this->oCI->xhtml->h1( $array_params['welcome_str'] );
		
		return $h1;
	}
}


# End of Qview class extension.
# -----------------------------
# o Contains the Qview registry statements
# o Contains the callback methods
# o That's it!


# Remember that the Qview extension is a CodeIgniter library. Save it in the
# appropriate folder and load it in your Controller class
# --------------------------------------------------------------------------
# + Some documentation reading might be needed if you don't know how to create
#   CodeIgniter libraries.

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


# Now you'll need a view file to trigger the callbacks
# ----------------------------------------------------


# In the view file...
# -------------------

# (1)
$this->my_qview->init();

# (2a)
$this->my_qview->head->attach()->title();

# (2b)
$this->my_qview->body->attach()->content();

# (3)
$this->my_qview->output();

# End of view file
# ----------------


# Lets examine the view file code
# -------------------------------
#
#  (1) : This calls the init method of our Qview extension. It registers the
#        triggers and callbacks
#
# (2a) : This triggers the callback method associated with the document part.
#        Notice the last statement in the chainig; 'title' in this example, it's
#        the trigger name we declared in the registration statement. When used
#        it calls the callback method associated with it. 
#
# (2b) : Same as (2a) except for body part.
#        Notice the statement parts:
#        o $this->
#          |      my_qview->
#          |      |         body->
#          |      |         |     attach()->
#          |      |         |     |         content();
#          |      |         |     |         |
#          |      |         |     |         +- Trigger name
#          |      |         |     |
#          |      |         |     +- Commands an attachment between the document
#          |      |         |        part and the returned content of the 
#          |      |         |        callback method through the trigger usage.
#          |      |         |
#          |      |         +- Document part. Available values are 'head' and
#          |      |            'body' only.
#          |      |
#          |      +- Library name. Go see CodeIgniter documentation for more info.
#          |
#          +- Need to say something?
#
#  (3) : Generates the Xhtml document and echoes an assembled XHTML string.


Thanks for looking. Email me for any information.

Recent activity

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.