<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ codeigniter - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ codeigniter - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Wed, 06 May 2026 17:00:21 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/codeigniter/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Develop with CodeIgniter on Ubuntu – Step-by-Step Environment Setup ]]>
                </title>
                <description>
                    <![CDATA[ CodeIgniter is a popular open-source PHP framework you can use to build dynamic and robust web applications. It’s simple to use, fast, and flexible. This makes it a good option for any developer who wants to have a light yet powerful framework that w... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-develop-with-codeigniter-on-ubuntu-environment-setup/</link>
                <guid isPermaLink="false">6793a7b71b1cdac77474f13a</guid>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ webdev ]]>
                    </category>
                
                    <category>
                        <![CDATA[ code ]]>
                    </category>
                
                    <category>
                        <![CDATA[ codeigniter ]]>
                    </category>
                
                    <category>
                        <![CDATA[ PHP ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ valentine Gatwiri ]]>
                </dc:creator>
                <pubDate>Fri, 24 Jan 2025 14:46:15 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1737640002689/7c78cd9c-40ef-45b3-82f6-97bc33f713d7.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>CodeIgniter is a popular open-source PHP framework you can use to build dynamic and robust web applications. It’s simple to use, fast, and flexible. This makes it a good option for any developer who wants to have a light yet powerful framework that will let them prototype or develop scalable applications fast.</p>
<p>Also, CodeIgnitor’s MVC (Model-View-Controller) architecture makes the process of organizing code and separating business logic from the user interface a piece of cake, yielding cleaner and maintainable projects.</p>
<p>Whether you’re building a small website or a complex application, CodeIgniter has a bunch of tools, libraries, and helpers that make the development process easier. They help you handle common tasks like database queries, session management, and form validation. Many devs love this tool because of its ease of use, making it an ideal framework for both beginners and experienced coders.</p>
<p>In this guide, I’ll walk you through the process of configuring CodeIgniter step by step, ensuring that you have a fully functional setup for your project on your local development environment.</p>
<h3 id="heading-prerequisites">Prerequisites</h3>
<p>Before getting started, make sure you meet the following requirements:</p>
<ul>
<li><p>Basic Knowledge of PHP: Understanding PHP syntax and basic programming concepts will help you follow along more easily.</p>
</li>
<li><p>Web Server (for example, Apache or NGINX): CodeIgniter needs a server to run. Make sure you have a working server set up on your local machine or hosting environment.</p>
</li>
<li><p>PHP Installed: You’ll need PHP 7.3 or higher (depending on the version of CodeIgniter you’re using).</p>
</li>
<li><p>Database System: CodeIgniter supports several databases, but MySQL is the most commonly used. Make sure you have access to a database system and know its credentials.</p>
</li>
<li><p>CodeIgniter Download: Download the latest version of CodeIgniter from the official website, GitHub repository, or use <code>composer</code> to install it.</p>
</li>
</ul>
<h2 id="heading-how-to-use-composer-to-install-codeigniter">How to Use Composer to Install CodeIgniter</h2>
<p>Now that you understand the prerequisites and have everything set up, let’s move on to installing CodeIgniter. One of the easiest and most efficient ways to install CodeIgniter is by using Composer, a popular dependency management tool for PHP. In this section, I’ll guide you through the steps to install CodeIgniter using Composer.</p>
<p>First, create a new directory using <code>mkdir my_project</code> then navigate to the directory using <code>cd my_project</code>. Run the following Composer command to install CodeIgniter. You can specify the version you want (e.g., <code>^4.0</code> for the latest version of CodeIgniter 4).</p>
<pre><code class="lang-bash">composer create-project codeigniter4/appstarter .
</code></pre>
<p>This command will download and install the latest version of CodeIgniter 4 and set up the project for you:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737222358773/c0be04da-c507-41cf-b98e-8c9126146b31.png" alt="CodeIgnitor download via composer output." class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>After the installation is complete, you should see the CodeIgniter project structure in your directory. To check if everything is working, you can start the built-in PHP server by running:</p>
<pre><code class="lang-bash">php spark serve
</code></pre>
<p>Output:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737224950979/8e7ccdac-ce8b-4b71-b41b-5ee02dfd9970.png" alt="Php spark serve output." class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>Then, open your browser and go to <a target="_blank" href="http://localhost:8080"><code>http://localhost:8080</code></a>. You should see the CodeIgniter welcome page.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737225118799/c7a38536-62fa-4788-814d-cd246a973691.png" alt="CodeIgnitor welcome page." class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<h2 id="heading-how-to-install-codeigniter-manually">How to Install CodeIgniter Manually</h2>
<p>If you prefer not to use Composer, or if you’re working in an environment where Composer isn’t available, you can manually install CodeIgniter. This method involves downloading the framework files directly and setting up your project manually. While it requires a few more steps than using Composer, it’s still straightforward and gives you full control over the installation process.</p>
<p>In this section, I’ll walk you through the steps to manually install CodeIgniter and configure it for your project.</p>
<p><strong>Download via Git:</strong></p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> /var/www/html
sudo git <span class="hljs-built_in">clone</span> https://github.com/bcit-ci/CodeIgniter.git codeigniter
</code></pre>
<p>Or <strong>download as ZIP (from CodeIgniter official website):</strong> <a target="_blank" href="https://www.codeigniter.com/download">Download here</a>. Extract it in <code>/var/www/html</code>. Whereby you can do so using the terminal or UI.</p>
<h3 id="heading-extracting-the-zip-file-via-the-ui">Extracting the ZIP File via the UI:</h3>
<p>If you’re not comfortable using command-line tools, you can easily extract the ZIP file using your computer’s graphical interface. Here's how:</p>
<p>Click on <code>files/Other Locations/computer</code> to access <code>/var/www/html</code>. Copy the <code>.Zip</code> file you downloaded earlier in the created folder and <code>right click</code>. Then click on <code>extract here</code> to unzip it.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737210782723/25317e2b-151b-491e-8e83-89c32d9cf5ee.png" alt="ZIP Extraction image." class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<h3 id="heading-extracting-the-zip-file-via-the-terminal">Extracting the ZIP File via the Terminal:</h3>
<p>If you’re comfortable using the command line, you can extract the CodeIgniter ZIP file directly via the terminal. This method is especially useful for Linux and macOS users or if you're working on a remote server without a graphical user interface.</p>
<p>First, ensure you have <code>unzip</code> installed on your Ubuntu system:</p>
<pre><code class="lang-bash">sudo apt update
sudo apt install unzip
</code></pre>
<p><strong>Check your permissions</strong> to ensure that you have the necessary access to the <code>/var/www/html</code> directory. If needed, use <code>sudo</code> for administrative privileges.</p>
<h3 id="heading-steps-to-extract-the-file">Steps to Extract the File</h3>
<p>Assuming your uploaded file is currently located in <code>downloads/data…</code>, move it to <code>/var/www/html</code>:</p>
<pre><code class="lang-bash">sudo mv /mnt/data/CodeIgniter.zip /var/www/html
</code></pre>
<p>Navigate to the <code>/var/www/html</code>directory:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> /var/www/html
</code></pre>
<p>Extract the ZIP file by using the <code>unzip</code> command to extract the contents:</p>
<pre><code class="lang-bash">sudo unzip CodeIgniter.zip
</code></pre>
<p>After extracting, set the correct ownership and permissions for web server access:</p>
<pre><code class="lang-bash">sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
</code></pre>
<blockquote>
<ul>
<li><p><code>www-data</code> (first part) → The <strong>user</strong>.</p>
</li>
<li><p><code>www-data</code> (second part) → The <strong>group</strong>.</p>
</li>
</ul>
</blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737212632072/6240acc1-27bd-49fe-acd4-5b3f80a92163.png" alt="Extracted folder(Codeigniter-develop) image." class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<blockquote>
<p>change <code>Codeigniter-develop /bcit-ci-CodeIgniter-bcb17eb/….</code>folder name to just codeigniter</p>
</blockquote>
<h3 id="heading-verify-extraction">Verify Extraction</h3>
<p>Visit your web server's URL (for example, <a target="_blank" href="http://localhost"><code>http://localhost</code></a>) to check if the contents are correctly deployed.</p>
<h3 id="heading-set-folder-permissions"><strong>Set Folder Permissions</strong></h3>
<p>After installing CodeIgniter, make sure you have the correct permissions for your directories, particularly <code>writable</code> and <code>cache</code> directories. This ensures that CodeIgniter can write logs, cache files, and session data.</p>
<p>Run the following commands to set the correct permissions:</p>
<pre><code class="lang-bash">sudo chmod -R 755 /var/www/html/codeigniter
</code></pre>
<h3 id="heading-configure-the-base-url"><strong>Configure the Base URL</strong></h3>
<p>The base URL for your project needs to be set up in <code>application/config/config.php</code>.</p>
<p>Open the <code>config.php</code> file:</p>
<pre><code class="lang-bash">sudo nano /var/www/html/codeigniter/application/config/config.php
</code></pre>
<p>Output:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737213372442/259f712f-2df4-4517-a382-88966b021950.png" alt="Config.php terminal image." class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>Set the <code>base_url</code> as follows:</p>
<pre><code class="lang-php">$config[<span class="hljs-string">'base_url'</span>] = <span class="hljs-string">'http://your-domain-or-ip/'</span>;
</code></pre>
<p>Replace <a target="_blank" href="http://your-domain-or-ip/"><code>http://your-domain-or-ip/</code></a> with your actual domain or IP address where the project will be accessible.</p>
<p>After making changes:</p>
<ul>
<li><p><strong>Save the file:</strong> Press <code>Ctrl + O</code> (Write Out).</p>
</li>
<li><p><strong>Confirm the filename:</strong> Press <code>Enter</code>.</p>
</li>
<li><p><strong>Exit the editor:</strong> Press <code>Ctrl + X</code>.</p>
</li>
</ul>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">You can also edit the files using UI by accessing them from <code>Other Locations//var/www/html/codeigniter</code></div>
</div>

<h3 id="heading-configure-the-database-if-applicable"><strong>Configure the Database (if Applicable)</strong></h3>
<p>If your project uses a database, you'll need to set up the database configuration in <code>application/config/database.php</code>.</p>
<p>To do this, open the database configuration file:</p>
<pre><code class="lang-bash">sudo nano /var/www/html/codeigniter/application/config/database.php
</code></pre>
<p>Configure the database connection by setting the following options:</p>
<pre><code class="lang-php">$db[<span class="hljs-string">'default'</span>] = <span class="hljs-keyword">array</span>(
    <span class="hljs-string">'dsn'</span>   =&gt; <span class="hljs-string">''</span>,
    <span class="hljs-string">'hostname'</span> =&gt; <span class="hljs-string">'localhost'</span>,
    <span class="hljs-string">'username'</span> =&gt; <span class="hljs-string">'your-db-username'</span>,
    <span class="hljs-string">'password'</span> =&gt; <span class="hljs-string">'your-db-password'</span>,
    <span class="hljs-string">'database'</span> =&gt; <span class="hljs-string">'your-database-name'</span>,
    <span class="hljs-string">'dbdriver'</span> =&gt; <span class="hljs-string">'mysqli'</span>,
    <span class="hljs-string">'dbprefix'</span> =&gt; <span class="hljs-string">''</span>,
    <span class="hljs-string">'pconnect'</span> =&gt; <span class="hljs-literal">FALSE</span>,
    <span class="hljs-string">'db_debug'</span> =&gt; (ENVIRONMENT !== <span class="hljs-string">'production'</span>),
    <span class="hljs-string">'cache_on'</span> =&gt; <span class="hljs-literal">FALSE</span>,
    <span class="hljs-string">'cachedir'</span> =&gt; <span class="hljs-string">''</span>,
    <span class="hljs-string">'char_set'</span> =&gt; <span class="hljs-string">'utf8'</span>,
    <span class="hljs-string">'dbcollat'</span> =&gt; <span class="hljs-string">'utf8_general_ci'</span>,
    <span class="hljs-string">'swap_pre'</span> =&gt; <span class="hljs-string">''</span>,
    <span class="hljs-string">'encrypt'</span> =&gt; <span class="hljs-literal">FALSE</span>,
    <span class="hljs-string">'compress'</span> =&gt; <span class="hljs-literal">FALSE</span>,
    <span class="hljs-string">'stricton'</span> =&gt; <span class="hljs-literal">FALSE</span>,
    <span class="hljs-string">'failover'</span> =&gt; <span class="hljs-keyword">array</span>(),
    <span class="hljs-string">'save_queries'</span> =&gt; <span class="hljs-literal">TRUE</span>
);
</code></pre>
<p>Replace <code>your-db-username</code>, <code>your-db-password</code>, and <code>your-database-name</code> with your actual database credentials.</p>
<h3 id="heading-set-the-environment"><strong>Set the Environment</strong></h3>
<p>CodeIgniter uses the environment setting to load different configuration files depending on the environment (for example, development, production).</p>
<p>To set the environment, open the <code>index.php</code> file in the root directory of your project:</p>
<pre><code class="lang-bash">sudo nano /var/www/html/codeigniter/index.php
</code></pre>
<p>Locate the following line:</p>
<pre><code class="lang-php">define(<span class="hljs-string">'ENVIRONMENT'</span>, <span class="hljs-string">'development'</span>);
</code></pre>
<p>You can set it to <code>production</code>, <code>testing</code>, or <code>development</code> depending on your setup. For development, it should be set to <code>development</code></p>
<h3 id="heading-autoload-libraries-helpers-or-config-files"><strong>Autoload Libraries, Helpers, or Config Files</strong></h3>
<p>You can specify which libraries, helpers, or config files to autoload in <code>application/config/autoload.php</code>. Open the autoload configuration file:</p>
<pre><code class="lang-bash">sudo nano /var/www/html/codeigniter/application/config/autoload.php
</code></pre>
<p>Modify the autoload array to load commonly used libraries and helpers:</p>
<pre><code class="lang-php">$autoload[<span class="hljs-string">'libraries'</span>] = <span class="hljs-keyword">array</span>(<span class="hljs-string">'database'</span>, <span class="hljs-string">'session'</span>, <span class="hljs-string">'form_validation'</span>);
$autoload[<span class="hljs-string">'helper'</span>] = <span class="hljs-keyword">array</span>(<span class="hljs-string">'url'</span>, <span class="hljs-string">'file'</span>);
</code></pre>
<h3 id="heading-enable-mod-rewrite-for-clean-urls"><strong>Enable Mod Rewrite (For Clean URLs)</strong></h3>
<p>If you want clean URLs, you need to enable <code>mod_rewrite</code> on Apache. Edit the Apache configuration file as follows:</p>
<pre><code class="lang-bash">sudo nano /etc/apache2/sites-available/000-default.conf
</code></pre>
<p>Ensure that the <code>AllowOverride</code> directive is set to <code>All</code> in the <code>&lt;Directory&gt;</code> section:</p>
<pre><code class="lang-bash">&lt;Directory /var/www/html&gt;
    AllowOverride All
&lt;/Directory&gt;
</code></pre>
<p>Enable mod_rewrite and restart Apache:</p>
<pre><code class="lang-bash">sudo a2enmod rewrite
sudo systemctl restart apache2
</code></pre>
<h3 id="heading-verify-codeigniter-directory-placement">Verify CodeIgniter Directory Placement</h3>
<p>If CodeIgniter is not in <code>/opt/lampp/htdocs</code>, move it there:</p>
<pre><code class="lang-bash">sudo mv /var/www/html/codeigniter /opt/lampp/htdocs/
</code></pre>
<h3 id="heading-test-codeigniter"><strong>Test CodeIgniter</strong></h3>
<p>Open your web browser and navigate to the base URL (<a target="_blank" href="http://your-domain-or-ip"><code>http://your-domain-or-ip</code></a>). You should see the default CodeIgniter welcome page if everything is set up correctly:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737218343140/7a41485a-152e-496e-9ba7-811e5c4b774b.png" alt="CodeIgniter welcome page." class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>Run <code>curl</code> <a target="_blank" href="http://ifconfig.me"><code>ifconfig.me</code></a> to find your public IP. If you're hosting CodeIgniter on a local machine (for example, in your home network), use the following command to check your local IP: <code>hostname -I</code>.</p>
<h2 id="heading-troubleshooting">Troubleshooting</h2>
<p>If you encounter any issues while setting up CodeIgniter, here are some common problems and how to resolve them:</p>
<h3 id="heading-set-codeigniter-as-the-default-app"><strong>Set CodeIgniter as the Default App</strong></h3>
<p>If you want CodeIgniter to load as the default app (instead of the XAMPP landing page if you have XAMPP installed), remove or rename the default <code>index.php</code> in the <code>htdocs</code> directory:</p>
<pre><code class="lang-bash">sudo mv /opt/lampp/htdocs/index.php /opt/lampp/htdocs/index.php.bak
</code></pre>
<p>Move the CodeIgniter files to the root of the <code>htdocs</code> folder:</p>
<pre><code class="lang-bash">sudo mv /opt/lampp/htdocs/codeigniter/* /opt/lampp/htdocs/
</code></pre>
<h3 id="heading-restart-apache"><strong>Restart Apache</strong></h3>
<p>After making changes, restart Apache to apply the configuration:</p>
<pre><code class="lang-bash">sudo /opt/lampp/lampp restart
</code></pre>
<h3 id="heading-creating-a-controller"><strong>Creating a Controller</strong></h3>
<p>To start developing your application, you can create a controller to handle requests.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737219751160/af7240e8-2793-45b9-9cff-1f9a74add34f.png" alt="Application folders." class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>Create a new controller in <code>application/controllers/</code> like this:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Welcome</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">CI_Controller</span> </span>{
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">index</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-keyword">$this</span>-&gt;load-&gt;view(<span class="hljs-string">'welcome_message'</span>);
    }
}
</code></pre>
<p>Then create Views and Models. Views go into <code>application/views/</code> and models into <code>application/models/</code>. You can start adding your views and models accordingly.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Setting up a development environment for CodeIgniter on Ubuntu is an essential step to unlock the full potential of this lightweight yet powerful PHP framework.</p>
<p>By carefully following the outlined steps—from installing prerequisites, configuring file permissions, and customizing settings to creating controllers, views, and models—you are now equipped to start building dynamic web applications.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to View CodeIgniter Log Files in the Browser ]]>
                </title>
                <description>
                    <![CDATA[ By Seun Matt Just like any other page, it is now possible to read CodeIgniter log files in the browser. My Sweet Goodness! Example view of code igniter log files I began using CodeIgniter in my day to day coding after joining an awesome company. The... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-view-codeigniter-log-files-in-the-browser-e4ec7a9e8b23/</link>
                <guid isPermaLink="false">66c355fed372f14b49bdcb6c</guid>
                
                    <category>
                        <![CDATA[ codeigniter ]]>
                    </category>
                
                    <category>
                        <![CDATA[ logging ]]>
                    </category>
                
                    <category>
                        <![CDATA[ open source ]]>
                    </category>
                
                    <category>
                        <![CDATA[ PHP ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 17 Jan 2018 23:09:59 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*gmHGclQeDOJ1jUM3zhfXKg.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Seun Matt</p>
<p>Just like any other page, it is now possible to read CodeIgniter log files in the browser. My Sweet Goodness!</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/d-k2Dfg0rgazIaeVdTY2NdzxgYN-2nUJxiQJ" alt="Image" width="600" height="400" loading="lazy">
<em>Example view of code igniter log files</em></p>
<p>I began using CodeIgniter in my day to day coding after joining an awesome company. The company’s tech stack includes the PHP Framework — among others. Hitherto now, I’ve used (<em>and still use</em>) Laravel to build some awesome apps.</p>
<p>Laravel has a great logging system that is simple and elegant. Furthermore, there’s a <a target="_blank" href="https://github.com/rap2hpoutre/laravel-log-viewer">library</a> for showing the logs in the browser. Being able to read the logs in the browser is good for application debugging and insight. Especially in a production environment.</p>
<p>So here I am in the world of CodeIgniter and couldn’t find an equivalent library to read my logs for debugging and insight.</p>
<p>So I took up the challenge and created my first Open Source project of the year — <a target="_blank" href="https://github.com/SeunMatt/codeigniter-log-viewer">codeigniter-log-viewer</a>.</p>
<h3 id="heading-usage">Usage</h3>
<p>First, let’s add it to a dependency. We can do that by executing:</p>
<pre><code>composer <span class="hljs-built_in">require</span> seunmatt/codeigniter-log-viewer
</code></pre><p>Then, we can create a CodeIgniter application controller, <em>LogViewerController.php</em>:</p>
<pre><code>private $logViewer;
</code></pre><pre><code>public <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__construct</span>(<span class="hljs-params"></span>) </span>{    $this-&gt;logViewer = <span class="hljs-keyword">new</span> \CILogViewer\CILogViewer();    <span class="hljs-comment">//...}</span>
</code></pre><pre><code>public <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">index</span>(<span class="hljs-params"></span>) </span>{    echo $this-&gt;logViewer-&gt;showLogs();    <span class="hljs-keyword">return</span>;}
</code></pre><p>What we did is to instantiate <em>$logViewer</em> in the constructor and then echo the result of <em>showLogs()</em> in the <em>index()</em> function.</p>
<p>The <em>showLogs()</em> method of <a target="_blank" href="https://github.com/SeunMatt/codeigniter-log-viewer">codeigniter-log-viewer</a> will parse the content of the log files in <em>application/logs</em> <em>.</em> It will return it for display on the browser.</p>
<p>Finally, we can map any route of our choice to the <em>index()</em> we created above. This can be done by adding an entry to the <em>$route</em> array in <em>application/config/routes.php:</em></p>
<pre><code>$route[<span class="hljs-string">'logs'</span>] = <span class="hljs-string">"logViewerController/index"</span>;
</code></pre><p>Now we can visit <em>/logs</em> on the browser and see all the log files there. It’s also possible to delete and download the log files.</p>
<p><strong>Note</strong>: It is advisable to use a protected route in production environment to avoid general public access.</p>
<h3 id="heading-how-it-works">How it works</h3>
<p>Internally, the library read the name of all the log files that are available in the default logs directory into an array and reverse it. If no file is specified in the URL query parameters, the latest log file is processed for display by default.</p>
<p>Processing of a log file for display involves reading its contents, using regex to determine the log level and the CSS class and icon of each entry.</p>
<p>Each entry is also checked to know if it’s a new log line or a continuation of the previous line (<em>due to a newline character</em>).</p>
<p>Finally, the log entries are processed into HTML content that is then sent to the browser for display.</p>
<p>The complete source code is available on Github if you want to play around with it or/and adapt it for use in other frameworks.</p>
<h3 id="heading-conclusion"><strong>Conclusion</strong></h3>
<p>Now it’s easier and faster to debug CodeIgniter application — even in production. Spread the word around to friends and colleagues at work.</p>
<p>I want to hear about your experience (<em>and opinions</em>) of using the library in the comment section. Thanks!</p>
<p>Visit the <a target="_blank" href="https://github.com/SeunMatt/codeigniter-log-viewer">Github Link</a></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
