You are currently viewing CodeIgniter tutorial for beginners

CodeIgniter tutorial for beginners

CodeIgniter tutorial

Let me tell you one thing, this coding is much easier than it seems. You must be thinking that what is this saying in coding and easy??? But I will decorate you in such an easy way that you will also find coding easy. So let’s get started.

I will tell you about an easy and very simple framework named CodeIgniter. I do not know what was happening in Hindi, so I wrote in English.

Let’s go ahead CodeIgniter is user friendly, you can download it for free, whose link I will give at the end of the article.
Before downloading CodeIgniter you need to install two things on your PC
1) xamp
2) IDE

Do you all know about Xamp?? If you do not know, then I will tell you about it in the article. Well this is a software that will host your PC like a server. It will run your PHP website and manage the database for you, this is a very small and cute software, it manages you database and your website through php my admin. Speaking in simple language, this is a connection, just your website database and hosting offline

Now let’s talk about the IDE. Why would everyone know this? do you know? Basically speaking IDE, then code editor like visual studio code, netbeans, etc.. IDE you can use whatever you like, I use Vs code.
Now let me tell you the steps to install

1) Download CodeIgniter, open it and extract it in C folder>xamp->htdoc and rename the folder with the name of your site.
2) Now open your xamp and start the above two options xamp and mysql

3) Now open your browser and open local host/websitename your website ready
If CodeIgniter did not start, then do not take tension if you get a 404 error open in the page of the Volcom message. go to your application folder go to waga config folder open the cofig.php file however you enter your website localhost + project or site name your website will start
Example http://localhost/mysite/

Now let’s move forward, now I will teach you to create your own web home page and will also teach you how to remove index.php from url, that too the easiest way.

Go to your Applications folder. Friends, let me tell you one thing, this is MVC base frame work. It means model, view and controller. As you have these three folders present in your application folder. We just have to play in it. So let’s open the view folder and create a file in it.
view folder
header.php
home.php
footer.php
controller folder
Home,php (first word must be capital all controller)

Friends, the controller is the URL of your website, so think give it the proper name of the society. CodeIgniter tutorial for you. As
http://localhost/mysite/home
https://example.com/home Home is a controller in this.

Friends, in CodeIgniter, the default is htpp://localhost/mysite/index.php/home index.php, we can remove it in the url, you just have to do two or three things.

.htaccess (creat this file in mysite main folder)

add this code inside this

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

config folder/autoload php

$autoload[‘helper’] = array(‘url’); //load this helper url

in config php

$config[‘base_url’] = ‘http://localhost/mysite/’;//you have to add this url
$config[‘index_page’] = ‘index.php’;// remove this index.php

in routes php

$route[‘default_controller’] = ‘home’;// remove welcome controller to
home controller
$route[‘404_override’] = ”;
$route[‘translate_uri_dashes’] = FALSE;

Now friends do coding in the home controller, you just have to load the view in it as in the coding below

home controller

<?php
defined(‘BASEPATH’) OR exit(‘No direct script access allowed’);
class Home extends CI_Controller {
    public function index()
    {
        $this->load->view(‘header’);
        $this->load->view(‘home’);
        $this->load->view(‘footer’);
    }
}

Friends, there are many ways to load the view, you can also do it with method chaining, we will do it in database work, you will understand well. how to install CodeIgniter.

Create your own view. Then open the website URL http://localhost/mysite , That’s all you have to put, you do not need to write Home, we have made Home the default controller, so above.

You can also do this using the Bootstrap starter template. Friends, in today’s time we do not need much to write Hutml, we would have got everything on Bootstrap 🙂

Learn How to Create Database

1) header php (views)

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

    <title>Hello, world!</title>
  </head>
  <body>
<!-- Bootstrap navbar -->

<nav class="navbar navbar-dark bg-primary">
  <a class="navbar-brand" href="#">Hello World!</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link</a>
      </li>
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown
        </a>
        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
          <a class="dropdown-item" href="#">Action</a>
          <a class="dropdown-item" href="#">Another action</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="#">Something else here</a>
        </div>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
      </li>
    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>

home php (views)

<h1>Hello, world!</h1>

footer php (views)

<!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
  </body>
</html>

load the page your page will be loaded

CodeIgniter tutorial Part 2

Friends, I want to tell one thing, if you are thinking that you will not be able to learn by reading a video or a blank post article because you will not understand until you do practical, then start a project with me. tutorial for CodeIgniter

If you have any problem, you can comment me here, I will answer you soon.
Thank you for reading my article carefully. Do write in the comment about whether you liked it or not.
Your developing friend Naveen
?
Have a nice day

Leave a Reply