CodeIgnitorV4-guide

This repo help user to install and setup CodeIgnitor

View on GitHub

Home

Static Pages Tutorial

This tutorial assumes you’ve downloaded CodeIgniter and installed the framework in your development environment.

Make our First Controller

cd
cd /var/www/html/ 
sudo mv your-file-name ci

- now check your folder is renamed or not by navigating /var/www/html/.

```console
cd
cd /var/www/html/ci/app/Controllers/
touch Pages.php
<?php

namespace App\Controllers;

class Pages extends BaseController
{
    public function index()
    {
        return view('welcome_message');
    }

    public function view($page = 'home')
    {
        // ...
    }
}

Note : if you are using vim editor(or wants to use vim : sudo apt-get install vim ) use press esc and then :wq to save and quit simlarly :q to quit without saving. Open file in vim use vim file_name. use arrow to nagigate.

cd
cd /var/www/html/ci/app/Views/
mkdir templates
cd templates/
touch header.php
<!doctype html>
<html>
<head>
    <title>CodeIgniter Tutorial</title>
</head>
<body>

    <h1><?= esc($title) ?></h1>
cd
cd /var/www/html/ci/app/Views/
mkdir templates
cd templates/
touch footer.php
    <em>&copy;Kumar Abhinav 2021</em>
</body>
</html>
cd
cd /var/www/html/ci/app/Views/
mkdir pages
cd pages
touch home.php
touch about.php
<?php
echo "Hello World"
?>
<?php
echo" Hello World I am about page ";
?>
<?php

namespace App\Controllers;

class Pages extends BaseController
{
    public function view($page = 'home')
    {
        if (! is_file(APPPATH . 'Views/pages/' . $page . '.php')) {
            // Whoops, we don't have a page for that!
            throw new \CodeIgniter\Exceptions\PageNotFoundException($page);
        }

        $data['title'] = ucfirst($page); // Capitalize the first letter

        return view('templates/header', $data)
            . view('pages/' . $page)
            . view('templates/footer');
    }
}
cd
cd /var/www/html/ci/app/Config/
$routes->get('pages', 'Pages::index');
$routes->get('(:any)', 'Pages::view/$1');

Happy Learning