Showing posts with label Codeigniter. Show all posts
Showing posts with label Codeigniter. Show all posts

Saturday, March 18

How to Insert Update Delete Retrieve data using Codeigniter in MySQL Database


When you are going to create a codeigniter web application using database you can not create it without using the insert, update, delete and retrieve codes of codeigniter. In this tutorial we will show you How to Insert Update Delete Retrieve data using Codeigniter in MySQL Database.

Thursday, February 23

How to add Twitter Bootstrap in PHP CodeIgniter

How-to-add-Twitter-Bootstrap-in-PHP-CodeIgniter
A fair design is always important to make your codeigniter web application more choiceable to the users. When you are a web developer and looking for creating a fair design, bootstrap is the best choice .Bootstrap framework has a lot of css classes for developing responsive, mobile-first web sites. Codeigniter and twitter bootstrap works together excellently. In this tutorial we will show you how to add twitter bootstrap in your codeigniter web application.

Requirements to Start:

There are three things you need to add Twitter Bootstrap in PHP CodeIgniter:
  1. Installation of a localhost server: To start this tutorial you need to install a localhost server in your computer. There are many options on the internet and you can download any of them. We will recommend you to use xampp server. Xampp server is a cross platform server application which will be the most useful for you. 
  2. Download CodeIgniter: You have to download the codeigniter source file to get you started. If you already have the source file then you can get started with that. If you don't have codeigniter source file then you can download it from their official website - https://www.codeigniter.com/download .You can also Download their Github repository from  - https://github.com/bcit-ci/CodeIgniter .
  3. Download Twitter Bootstrap: You need the bootstrap compiled and minified file to get started. If you  have already downloaded bootstrap compiled and minified file then you have no problem to start with that. Other wise you can download the current version of bootstrap from their official website - http://getbootstrap.com/getting-started/#download .By opening this link you will see a button - 'Download Bootstrap'. Click on that button and proceed.
Now follow the bellow mentioned steps to add Twitter Bootstrap in your PHP CodeIgniter web application:

  1. Set up of Codeigniter
  2. Addition of Bootstrap file On Your Project
  3. Creation of Layout Page
  4. Link of Bootstrap on Layout Page
  5. Addition of HTML
  6. Checking of Output

Set up of Codeigniter

In order to add Twitter Bootstrap in your PHP CodeIgniter web application The first step you need to follow is setting up of Codeigniter on your web server or localhost. Set up your base url in 'config.php' file and set up url and file helper in 'autoload.php' file.For this tutorial we will not use any database, so you don't need to configure database. However, if you don't know how to configure base url and helpers in codeigniter you can check the tutorial - How to Install and Configure Codeigniter.

Addition of Bootstrap file On Your Project

Go to the root of your codeigniter project. Create a new folder 'template'. On this 'template' folder you will keep all bootstrap files that you have downloaded from the given link. After extract the bootstrap zip file you will get three folders: css, fonts and javascript. Copy and paste them on 'template' folder that you have created on the root of your codeigniter project.
Bootstrap-CodeIgniter-tutorial

Creation of Layout Page:

 You have to create a layout page - 'layout.php' in our application >> views folder to write some bootstrap integrated html codes.To make 'layout.php' visible you need to write some functions in your controller. Go to application >> controllers and open 'Welcome.php'. Write the bellow code:

public function layout()
{  
  $this->load->view('layout');
}

Link of Bootstrap on Layout Page:

To link bootstrap stylesheet that you have added on your project, open  'layout.php' from application >> views folder and copy bellow code inside the head section.


<title>Twitter Bootstrap integration on PHP CodeIgniter</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="<?php echo base_url();?>template/css/bootstrap.min.css">
<script src="<?php echo base_url();?>template/js/bootstrap.min.js"></script>

Addition of HTML:

You need to write some html and bootstrap codes on 'layout.php' to check whether your bootstrap links are working properly or not. Add the bellow code inside  the body tag of 'layout.php'.

<div class="container">
    <div class="row">
      <div class="col-md-4">
        <h3>Responsive Column 1</h3>
        <p>Resize to see the effect</p>
      </div>
      <div class="col-md-4">
        <h3>Responsive Column 2</h3>
        <p>Resize to see the effect</p>
      </div>
      <div class="col-md-4">
        <h3>Responsive Column 3</h3> 
        <p>Resize to see the effect</p>
      </div>
    </div>
  </div>

To minimise your complexity  we have  written bellow the entire code of 'layout.php'. If you feel any trouble to grasp the method You can also write the entire code in 'layout.php' as mentioned bellow .

<html lang="en">
<head>
  <title>Twitter Bootstrap integration on PHP CodeIgniter</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="<?php echo base_url();?>template/css/bootstrap.min.css">
  <script src="<?php echo base_url();?>template/js/bootstrap.min.js"></script>
</head>
<body>
  <div class="container">
    <div class="row">
      <div class="col-md-4">
        <h3>Responsive Column 1</h3>
        <p>Resize to see the effect</p>
      </div>
      <div class="col-md-4">
        <h3>Responsive Column 2</h3>
        <p>Resize to see the effect</p>
      </div>
      <div class="col-md-4">
        <h3>Responsive Column 3</h3> 
        <p>Resize to see the effect</p>
      </div>
    </div>
  </div>
</body>
</html>

Checking of Output

Open layout page from any browser to check if bootstrap style is added with codeigniter or not. If you see something like bellow it happens that you have added successfully the Twitter Bootstrap in PHP CodeIgniter.
Bootstrap-CodeIgniter-tutorial
Now resize your browser to see the responsive effects.

So these are the 6 simple steps to add Twitter Bootstrap in PHP CodeIgniter. If you need any further assistance you can freely comment bellow.We love helping our viewers to solve their problems.

We hope our tutorial on 'How to add Twitter Bootstrap in PHP CodeIgniter' will help you design great applications. If you liked this article, then please subscribe our newsletters for daily updates.

Monday, February 20

How to Install Codeigniter in Localhost

Codeigniter-Installation-Spicy-Loop
Codeigniter is a popular open source web application development framework created for php developers. It use the MVC (model-view-controller) Architecture pattern. The codeigniter framework offers many helpful code libraries and helpers to speed up development of php applications. In this tutorial we will show you how to install codeigniter in your localhost.

Requirement to start:

There are two things you need to start codeigniter installation in your localhost :
  1. Install a localhost server In your computer. There is many options e.g. wamp, xampp, lampp and you can download any of them. We will recommend you to use xampp server. Xampp server is a cross platform server application. Most of the web server companies use xampp. So when you go to upload your application on the web server you will use xampp.
  2. To start with codeigniter installation you have to download the codeigniter source file. If you have already downloaded codeigniter then you can get started with that. Other wise you can download it from their official website - https://www.codeigniter.com/download .You can also Download their Github repository from  - https://github.com/bcit-ci/CodeIgniter .

In this tutorial, we will go with 5 simple steps :
  1. Installing and Exploring CodeIgniter
  2. Configuring CodeIgniter
  3. Testing CodeIgniter
  4. Configuring Libraries and Helpers
  5. Configuring Database

 

Installing and Exploring CodeIgniter:

Once you download codeigniter from the provided download link you will receive a .zip file.Unzip and rename that folder as your project name.Now copy and pest that folder to your php and mysql server location.We are using Xampp server for making applications, so we copy it to the 'htdocs' folder of 'xampp'.If you are using Wamp server then you need to copy it to 'www' folder of 'wamp'.

 

Configuring CodeIgniter:

You need to set up the right base url to run your application. To set up a base url go to the location application>>config. Inside of the 'config' folder there will be a file 'config.php'. Open that file on your favourite text editor. Search for the bellow line.

$config['base_url'] = '';

Now copy and pest your application url inside of the single quote.As an example:

$config['base_url'] = 'http://localhost/your_project_folder_name';

 

Testing CodeIgniter:

Now we will check the CodeIgniter application is running properly or not. Open your application url from the browser. If your browser opens the bellow page it means your application running properly.

Codeigniter-Installation-Spicy-Loop

Configuring Libraries and Helpers:

Codeigniter provides two features to help programmers to create applications. One is library and other one is helper.Library class is a collection of tools and helper is a collection of functions in a particular category. You need to specify which library and helper you want to use in application.To do this go to the location application>>config and open 'autoload.php' file on your favourite text editor.Now search for the bellow line :

$autoload['helper'] = array();

Write the name of helper file inside of the array.As for example :
$autoload['helper'] = array('url', 'file');


Configuring Database:

To connect your codeigniter application with MySQL database go to the location application>>config and open 'database.php' file on your favourite text editor do the changes as bellow.

 $db['default'] = array(
 'dsn' => '',
 'hostname' => 'localhost',
 'username' => '',// Write your Database User Name inside of the single quote
 'password' => '',// Write Password of your Database User Name inside single quote
 'database' => '',// Write Database name inside of the single quote
 'dbdriver' => 'mysqli',
 'dbprefix' => '',
 'pconnect' => FALSE,
 'db_debug' => (ENVIRONMENT !== 'production'),
 'cache_on' => FALSE,
 'cachedir' => '',
 'char_set' => 'utf8',
 'dbcollat' => 'utf8_general_ci',
 'swap_pre' => '',
 'encrypt' => FALSE,
 'compress' => FALSE,
 'stricton' => FALSE,
 'failover' => array(),
 'save_queries' => TRUE
);

After connecting your codeigniter application with Database you are ready to perform database activities like insert, update, delete.

So this are the 5 simple steps to configure Codeigniter in your Localhost. Follow those 5 steps and start creating great applications.

We hope our tutorial on How to Install Codeigniter in Localhost will help you to get started with codeigniter.If this tutorial don't answer your question you can ask your question on the comment section bellow. We love helping our viewers to solve their problem.

If you liked this article, then please subscribe our newsletters for daily updates.


Thursday, February 16

How to Remove index.php From url in Codeigniter using htaccess

codeigniter-remove-index-php
CodeIgniter urls are designed to be search-engine and human friendly.But, that by default 'index.php' which appears in the url of codeigniter applications is really awkward.To maintain the standards I always  remove the default 'index.php' from the codeigniter url so that the url becomes more search engine friendly and looks clean.
So today in this tutorial I will show you how to remove index.php from codeigniter url.
That 'index.php' can be removed from the codeigniter url by following some simple steps.First we will create an '.htaccess' containing codes to remove 'index.php' from the codeigniter url.We will save that '.htaccess' file on root of that codeigniter applications. We will also make necessary changes on the configuration files of that codeigniter application.It is as simple as bellow :

Step I - Download Codeigniter : You can download Codeigniter 3  from their official website - https://www.codeigniter.com/download .You can also Download Github repository of Codeigniter 3  - https://github.com/bcit-ci/CodeIgniter .

Step II - Create .htaccess File : The next step is create an '.htaccess' file.First open your favourite text editor and create a new text file.Now save it as ".htaccess" in the root directory of that codeigniter application. Some time the file saved as a text file. To avoid this problem type the file name within quotes.
codeigniter-remove-index-php

Now copy paste bellow code to the '.htaccess' file and save:

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

Step III - Modify Config.php File : Now in the next step we will make some changes on the 'config.php' file. Go to application>>config folder of your codeigniter application.Open the file 'config.php'.
First Search for the bellow line in 'config.php'.

$config['index_page'] = 'index.php';

Replace this line with the bellow line

$config['index_page'] = '';

Again Search for the bellow line in 'config.php'.

$config['uri_protocol'] ='AUTO'

Replace this line with the bellow line

$config['uri_protocol'] = 'REQUEST_URI'

Now try to open your codeigniter application without 'index.php'. Hope it will open your application without 'index.php'. If your fell any problem on following those steps comment bellow. Thanks for reading this article. 

Wednesday, January 18

How to upload images using Codeigniter 3 and save them into MySQL database

codeigniter-image-upload

Image upload is the most important chapter in Web Development. I am creating Web applications from last 3 years using codeigniter and one of the most frequently used codes in my projects is uploading images and save them into the database.So today I will show you how to upload images using codeigniter 3 and save them on the database.