Location: PHPKode > scripts > ANM_CI > anm_ci/anm_ci.php
<?php
/**
* @author A.N.M. Saiful Islam <hide@address.com>
*
* @copyright © 2008-2009 A.N.M. Saiful Islam
*
* @license license.txt <The MIT License>
*
* @version 0.9.0
*
* @link http://anmsaiful.net/blog/category/anm_class/anm_ci.html
*/


/**
*	Integrating CodeIgniter with ANM technology
*
*	@package ANM_CI
*
*	@final
*/
final class ANM_CI
{
	/**
	*	Instance of the main CodeIgniter object
	*
	*	@var ci
	*
	*	@access public
	*/
	var $ci;



	/**
	*	---------------------------------------------------------------------------------------
	*	Remap given method according to given remap rules
	*
	*	@param string method Typically second segment of the URI
	*
	*	@param array rules Rules to decide which method will be called by which name
    *
	*	@param string default Method which will be called if requested method is not available
	*
	*	@return No value is returned
	*
	*	@access public
	*	---------------------------------------------------------------------------------------
	*/
    function remap( $method, $rules, $default = NULL )
    {
        // Call given method
        if( isset($rules[$method]) ) {
            $this->ci->$rules[$method]();

        // Call default method from third parameter
        } else if( isset($default) ) {
            $this->ci->$rules[$default]();

        // Call default method from given rules
        } else if( isset($rules['default']) ) {
            $this->ci->$rules['default']();
        }
    }



	/**
	*	----------------------------------
	*	Redirect current page to given URI
	*
	*	@return No value is returned
	*
	*	@access public
	*	----------------------------------
	*/
    function redirect( $uri = '', $method = 'location', $http_response_code = 302 )
    {
        // Load URL helper
        if( ! function_exists( 'redirect' ) ) {
            $this->ci->load->helper( 'url' );
        }

        // Redirect to given uri using CodeIgniter's redirect function
		redirect( $uri, $method, $http_response_code );

        // Initialize redirection URI
        $uri = site_url( $uri );

        // Redirect to given uri using HTML meta tag
        echo '<meta http-equiv="refresh" content="0; URL='.$uri.'">';

        // Redirect to given uri using JavaScript
        echo '<script language="JavaScript">document.location='.$uri.'</script>';

        // Display redirection link if current page does not redirect automatically
        $style   = '#redirect{padding:20px;color:#060;font:normal 12px Verdana;border:1px #3ca03c solid;background-color:#f0fff0} #redirect b.title{font:bold 18px Verdana;display:block;margin-bottom:10px;} #redirect a{color:#060;font-weight:bold;text-decoration:none} #redirect a:hover{color:#d00;text-decoration:underline}';
        $message = '<div id="redirect"><b class="title">Redirecting...</b>If you do not redirect autometically please <a href="'.$uri.'">click here</a> to continue.</div>';
        $output  = '<html><head><style type="text/css">'.$style.'</style></head><body>'.$message.'</body></html>';
        echo $output;
        exit;
    }



	/**
	*	-----------------
	*	Class constructor
	*	-----------------
	*/
	function ANM_CI()
	{
        // Being an instance of the main CodeIgniter object
        $this->ci = & get_instance();
	}
}
?>
Return current item: ANM_CI