Location: PHPKode > scripts > ANM_CI > anm_ci/docs/anm_ci_manual.html
<html>
<head>
    <title>ANM_CI – CodeIgniter Integration Library</title>
    <link rel='stylesheet' type='text/css' href='style.css' />
</head>
    <div id='manual'>
        <h1>ANM_CI – CodeIgniter Integration Library</h1>
        <div class='hr'></div>

        <h2>Table of Contents</h2>
            <h3>Getting Started</h3>
            <ul>
                <li><a href='#introduction'>Introduction</a></li>
                <li><a href='#download'>Download</a></li>
                <li><a href='#installation'>Installation</a></li>
                <li><a href='#how-to-use'>How to Use?</a></li>
                <li><a href='#change-log'>Change Log</a></li>
                <li><a href='#license'>License</a></li>
                <li><a href='#credit'>Credit</a></li>
            </ul>
            <h3>References</h3>
            <ul>
                <li><a href='#property-reference'>Property Reference</a></li>
                <ul>
                    <li><a href='#property-ci'>ci</a></li>
                </ul>
                <li><a href='#method-reference'>Method Reference</a></li>
                <ul>
                    <li><a href='#method-remap'>remap</a></li>
                    <li><a href='#method-redirect'>redirect</a></li>
                </ul>
            </ul>
            <small>[ <a href='#top'>Back to top</a> ]</small>
            <div class='hr'></div>

            <h2><a name='introduction'>Introduction</a></h2>
            <p class='aj'><a target='_blank' href='http://anmsaiful.net/blog/anm_class/anm_ci.html'><b>ANM_CI</b></a> is a <a target='_blank' href='http://php.net'><b>PHP</b></a> class which is developed to use as a <a target='_blank' href='http://codeigniter.com'><b>CodeIgniter</b></a>'s user library. This library integrates CodeIgniter with <b>ANM technology</b> which is able to achieve 100% satisfaction of programmers while using CodeIgniter because of its efficiency, simplicity and usefulness. I encourage you to use the library to see that how it makes your life so easy & comfortable.</p>
            <small>[ <a href='#top'>Back to top</a> ]</small>
            <div class='hr'></div>

            <h2><a name='download'>Download</a></h2>
            <table>
                <tr><th>Version</th><th>Release</th><th>File Name</th><th>File Size</th><th>Download</th></tr>
                <tr><td style='vertical-align:middle' rowspan='2'><b>0.9.0</b></td><td style='vertical-align:middle' rowspan='2'>28 March, 2009</td><td>anm_ci-0.9.0.zip</td><td>6.65 KB</td><td><a target='_blank' href='http://anmsaiful.net/downloads?file=MjM2OTEzNDc4OTc4'>Download</a></td></tr>
                <tr><td>anm_ci-0.9.0.tar.gz</td><td>5.37 KB</td><td><a target='_blank' href='http://anmsaiful.net/downloads?file=NzU4OTMyODY1Njk4'>Download</a></td></tr>
            </table>
            <small>[ <a href='#top'>Back to top</a> ]</small>
            <div class='hr'></div>

            <h2><a name='installation'>Installation</a></h2>
            <ul>
                <li>Download the ANM_CI compressed library (zip/tar.gz) and uncompress it.</li>
                <li>After uncompress you will have a directory named <b>anm_class</b> with following structure:</li>
                <ul>
                    <li><b>anm_ci.php</b> - the ANM_CI library</li>
                    <li><b>license.txt</b> - license of the library</li>
                    <li><b>docs</b> – documentation directory</li>
                    <ul>
                        <li><b>anm_ci_manual.html</b> - user guide for the library</li>
                        <li><b>style.css</b> - stylesheet of the user guide</li>
                        <li><b>anm_ci_example.php</b> – an example controller implementing all the properties and methods of ANM_CI</li>
                    </ul>
                </ul>
                <li>Now place the directory under<br /><span class='highlight'>{codeigniter_system_dir}/application/libraries</span></li>
            </ul>
            <small>[ <a href='#top'>Back to top</a> ]</small>
            <div class='hr'></div>

            <h2><a name='how-to-use'>How to Use?</a></h2>
            <p class='aj'>
                <p>To load the library simply use CodeIgniter's <b>loader</b> class.<pre class='highlight'>$this->load->library( 'anm_class/anm_ci' );</pre></p>
                <p>You can also set it as CodeIgniter's <b>auto-loading</b> resource. To do it just open the <b>autoload.php</b> file from<span class='highlight'>{codeigniter_system_dir}/application/config</span></p>
                <p>and add <b>'anm_class/anm_ci'</b> as an array element of <b>$autoload['libraries']</b><pre class='highlight'>$autoload['libraries'] = array('anm_class/anm_ci');</pre></p>
                <p>Once you include it in auto-loading library list then you don't need to load the class in your script.</p>
                <p>Now use the library as follows:<pre class='highlight'>$this->anm_ci->remap( $method, $rules );</pre></p>
            </p>
            <small>[ <a href='#top'>Back to top</a> ]</small>
            <div class='hr'></div>

            <h2><a name='change-log'>Change Log</a></h2>
            <ul>
                <li>This is <b>first release</b>, so no changes yet.</li>
            </ul>
            <small>[ <a href='#top'>Back to top</a> ]</small>
            <div class='hr'></div>

            <h2><a name='license'>License</a></h2>
            <p class='aj'>This library is licensed under <b>The MIT License</b> which is given with this library. If not available please visit <a target='_blank' href='http://www.opensource.org/licenses/mit-license.php'><b>http://www.opensource.org/licenses/mit-license.php</b></a></p>
            <small>[ <a href='#top'>Back to top</a> ]</small>
            <div class='hr'></div>

            <h2><a name='credit'>Credit</a></h2>
            <p class='aj'>ANM_CI is developed by <a target='_blank' href='http://anmsaiful.net'><b>A.N.M. Saiful Islam</b></a> who is a Computer Science Graduate and currently working as a Software Engineer with Future Group Bangladesh.</p>
            <small>[ <a href='#top'>Back to top</a> ]</small>
            <div class='hr'></div>

            <h2><a name='property-reference'>Property Reference</a></h2>
            <ul>
                <li><b><a href='#property-ci'>ci</a></b> - Instance of the main CodeIgniter object</li>
            </ul>
            <small>[ <a href='#top'>Back to top</a> ]</small>
            <div class='hr'></div>

            <h2><a name='method-reference'>Method Reference</a></h2>
            <ul>
                <li><b><a href='#method-remap'>remap</a></b> - Remap given method according to given remap rules</li>
                <li><b><a href='#method-redirect'>redirect</a></b> - Redirect current page to given URI</li>
            </ul>
            <small>[ <a href='#top'>Back to top</a> ]</small>
            <div class='hr'></div>

            <h2><a name='property-ci'>ci</a></h2>
            <h3>Description</h3>
                <p class='aj'>
                    <p>This is an instance of main CodeIgniter object. It is a <b>public property</b>. So you can use it anywhere where anm_ci library is accessible.</p>
                    <p>Typically <b>this</b> object is used to load and access CodeIgniter recourses like library, view, model, database, scaffolding, vars, helper, plugin, file, lang, config etc. You can use the above <b>ci</b> object as an alternate of the CodeIgniter's this object.</p>
                </p>
            <h3>Example</h3>
                <pre class='highlight'>$this->anm_ci->ci->load->model('Model_name');</pre>
                is equivalent of
                <pre class='highlight'>$this->load->model('Model_name');</pre>
            <h3>Note</h3>
                <p class='aj'>You'll notice that the <b>ci</b> property is being passed by reference. This is very important. Assigning by reference allows you to use the original CodeIgniter object rather than creating a copy of it.</p>
            <small>[ <a href='#top'>Back to top</a> ]</small>
            <div class='hr'></div>

            <h2><a name='method-remap'>remap</a></h2>
            <p><b>remap( string method, array rules [, string default] )</b></p>
            <h3>Parameters</h3>
                <ul>
                    <li><b>method</b> - Typically second segment of the URI</li>
                    <li><b>rules</b> - Rules to decide which method will be called by which name</li>
                    <li><b>default</b> - Method which will be called if requested method is not available</li>
                </ul>
            <h3>Description</h3>
                <p class='aj'>
                    <p>The remap method integrates CodeIgniter's built in <b>_remap</b> method which is used to overwrite the behavior of calling controller methods over URI. To know details about using the _remap method you can read the article: <a target='_blank' href='http://anmsaiful.net/blog/codeigniter/codeigniter-remap-power-benefit.html'><b>CodeIgniter _remap method – Power and Benefits</b></a>.</p>
                    <p>Typically programmers design the _remap method using multiple if-else or switch control structure so that the _remap method looks like:</p>
<pre class='highlight'>
function _remap( $method )
{
  switch( $method ) {
    case 'index':
      $this->index();
      break;

    case 'contact':
      $this->contact_us();
      break;

    default:
      $this->page_not_found();
      break;
  }
}</pre>
                    <p>But while using ANM_CI you will use an <b>associative array</b> as the alternate of the multiple if-else or switch control structure. The examples from bellow explain the implementation of the above script in terms of ANM_CI technique.</p>
                </p>
            <h3>Example</h3>
                <p><b>Using 'default' router rule:</b></p>
<pre class='highlight'>
function _remap( $method )
{
  $rules = array(
    'index'   => 'index',
    'contact' => 'contact_us',
    'default' => 'page_not_found'
  );

  $this->anm_ci->remap( $method, $rules );
}
</pre>
                <p><b>Using third parameter:</b></p>
<pre class='highlight'>
function _remap( $method )
{
  $rules = array(
    'index'     => 'index',
    'contact'   => 'contact_us',
    'not-found' => 'page_not_found'
  );

  $this->anm_ci->remap( $method, $rules, 'not-found' );
}
</pre>
            <h3>Note</h3>
                <p class='aj'>If you use a <b>'default'</b> key in your rules array, the value of default key will be considered as default method which you can also pass in the optional <b>third parameter</b>. If you use third parameter then default key will be ignored as default method. Here default method is the method which will be called if requested method is not available.</p>
            <small>[ <a href='#top'>Back to top</a> ]</small>
            <div class='hr'></div>

            <h2><a name='#method-redirect'>redirect</a></h2>
            <p><b>redirect( [string uri [, array method [, int http_response_code]]] )</b></p>
            <h3>Parameters</h3>
                Same as CodeIgniter's redirect helper function.
            <h3>Description</h3>
                <p class='aj'>It works same as CodeIgniter’s redirect helper function. The extra benefit is, if CodeIgniter’s redirection does not work properly it tries to redirect using <b>HTML meta tag</b> and <b>JavaScipt</b>. If all the above attempts fail then it displays a redirection <b>message</b> with a link of the redirection URL.</p>
            <h3>Example</h3>
<pre class='highlight'>
function index()
{
  $this->anm_ci->redirect( 'home-page' );
}
</pre>
            <small>[ <a href='#top'>Back to top</a> ]</small>
    </div>
</html>
Return current item: ANM_CI