Monday, March 20, 2017

How to Use Custom Validation in Codeigniter Form



Hello Friends,
                       Today I am  bought you that   how you can add the Custom Validation in the form your are working on , as Codeigniter define their validation in their in-built form validation class but what if i wan't to add my own custom rules in the validation of a form.


Below is the screenshot of a form which i have already made and in this i am going to tell you how you can add your custom validation rules in the form.

I have made a class name form and in this we are calling the index function as you all know that the codeigniter always calls the index function of any controller so in this we are calling the index function and inside this function we are going to do the validation 


<?php
class Form extends CI_Controller {
        public function index()
        {          
                // Validation code come here 		
        }
}

?>


Now from here i am going to tell you how we can add our custom rules in Codeigniter Form.

First of all we have to load the library which we required in the form validation and same we declare in the code  in the above . the line which we add is given below

 $this->load->helper(array('form', 'url'));

// this code is use the helper for the form which we require.

 $this->load->library('form_validation');

// the above line of code tells the codeigiter to load the library for Form Validation which we require in this problem .
After adding the


two lines the code comes like this.



<?php
class Form extends CI_Controller {
        public function index()
        {          
               $this->load->helper(array('form','url,'));
               $this->load->helper('form_validation');
        }
}
?>

Now, After loading the library and the helper class we need to do validation for our fields.
 The syntax here we use is given below

$this->form_validation->set_rules('Field Name','Field Title','Rules')


Field Name is the name of the text field which you have taken in the form.
Field Title is the title which you want to given while validating the text Field.
Rules is the Rules for the validation you define for the particular field such as require or valid email.

So in our form in the screenshort above we have three field namd User Name, Password and the last Field is Email Address. We have taken username,password and the email as their field name in the form which we are going to validate.
So now we add aour rules for these fiels
For Username we write the code as given below,

$this->form_validation->set_rules('username','User Name','trim|required|min_length[6]');


As for the User Name we write the same code for validation for the other fields and when we combine the code your can see the code like this as shown below.

<?php
class Form extends CI_Controller {
        public function index()
        {          
          $this->load->helper(array('form','url,'));
          $this->load->helper('form_validation');
          $this->form_validation->set_rules('username','User Name','trim|required|min_length[6]'); // Validation for username field
          $this->form_validation->set_rules('password','Password ','trim|required');  // Validation for password field
          $this->form_validation->set_rules('email','Email Id','trim|required|valid_email'); / Validation for email Id field
          
          if ($this->form_validation->run() == FALSE)
           {						
            $this->load->view('myform'); // redirected to back to the form page
           }
           else					 
           {
           echo 'Success!'; // This is the success message when validation rules fulfilled.
           }
        }
}
?>
After when you try to submitted the form you get the error in form like this as shown in the screenshort given below



If you want to change the field name you are free to change and in the form validation rules you can change the field name which field you are going to validate in the form.

Tuesday, January 10, 2017

Application Flow Chart of Codeigniter Application


Hello Friends,
                       Today I am  bought you the  cycle of codeigniter application how the request is made to the controller and how the controller interact with the route and the Model in order to run the application completely i show you with the application Flow chart of Codeigniter how it's take request and  send a response on to the browser as shown below and also tell  you how the applciation flow chart works when someone request it.





       Codeigniter Application Flow Chart


Step-1 :-In each and every Application Index.php page server as the first page of any application based on php as we are here talking about the codeigniter so as here the index.php server as the entry point of the application flow chart. It basically initializing the base resources needed to run the Codeigniter.


Step-2 :-  Here in the diagram you can see the word Routing in the Green Box. Basically Routing server the HTTP request which are coming from the index.php  and Routing is the one who determine what action will be fire as per the HTTP request which he been receiving from the Index.php page of the Application.


Step-3 :-  Below the Routing you can see the Caching Box which is basically used for caching . here if the cache file exists in the applciation the routing does not process further but it bypass the normal flow system of the application and move the the caching file and send it to the Browser Directly.


Step-4After this there is a Security Module which is loaded first before any Controller of the Application is loaded. Any request comes  or any data submitted to the application is filtered through the Security module of the Application.


Step-5 :-Now the main portion of the Application is the Application Controller which server the request coming from index.php through route to the controller. The controller of the Application  loads the loads the model, core libraries, helpers, and any other resources needed to process the specific request.


Step-6 :- The Final step is the View Module which is rendered then sent to the web browser to be seen. If caching is enabled, the view is cached first so that on subsequent requests it can be served.


Tuesday, December 27, 2016

MVC Framework Such as Codeignitor

Hello Friends ,

There are various types of MVC Framework avaiable in the market such as Codeignitor,Laravel,cakephp and many more.Today i tell you why the MVC Framework is more popular in php as any other in php. Building software application can be complex, time consuming process, however utilizing a framework can help you develop projects faster and work better. Using a framework also facilitates scalability and long term maintaince by complying with development standards, keeping your code organized and allowing your application to evolve and grow over time.

                                                      By removing the time and efforts required to build generic components, you can dedicate more time to specific tasks and functionality, and focus on sustainable, high-quality code. We've identified many framework in the market which is avaiable today such as CodeIgniter.Before jumping to CodeIgniter lesson we first want to know that what is MVC.

What is MVC ?

The Model-View-Controller (MVC) is an architectural pattern that separates an application into three main logical components: the model, the view, and the controller. Each of these components are built to handle specific development aspects of an application. MVC is one of the most frequently used industry-standard web development framework to create scalable and extensible projects.




Codeigniter Key Features

a) Model-View-Controller Based System :-  CodeIgniter makes use of MVC System to find complex  models  and helps you to create application easily by  using controllers and views. It assists the developer to build  
core libraries for the sysrem and enables you to integrate your own existing  scripts with database.

b) Error Handling :- If offers simple user-friendly interfaces that help you to detect error functions throughout the application globally In this way of approach, it provides instructions to error  logging class
that allows debugging messages to be saved as text files. It displays all PHP errors in your web application without missing inadequancy.

c) Form Validation :- This features helps you to write the error code in a single line by using effective validation framework system. It generates code without any errors and ensures various control structures to be placed within the HTML form.

d) Migrations :- Developers can manage database schema updates across various web applciation fields easily with help of the migrate aspect. Migration from one server to another server is simple and hassle-free in CodeIgniter.

d) Configuration and Customizable :- This aspect helps the developers to create what they need to develop based on the web applications. You can edit the existing files in CodeIgniter easily and it does not confuse beginners to develop a new life. In addition, configuration and customizable of the files are easy in this frameworks.


CodeIgniter is a very simple and usable toolkit that comprehensively serves you with many benefits
  • As Codeigniter is an Open Source Framework, is is really simple to configure.
  • It is easy to learn, adopt and deploy.
  • It allow you to easily do customization for your own requirements.
  • It simplifies the PHP syntax.
  • Is makes codeing in PHP very simple,quick and easy to use.
  • It is a brilliant framework used to learn more about how PHP works.
  • It allows you to streamline the code underlying your web pages easily.
  • You can apply a new functionality that doesn’t affect the customization at all.
  • Active Record Implementation is outstanding and easy to remember.
  • Excellent documentation of the user guide that helps coders to use the entire framework easily.
  • It enables to integrate its own existing scripts and develop core libraries for the system.
  • CodeIgniter uses a direct approach while handling models. The workings of CodeIgniter are very clear as well as open, hence it is easily understandable what is happening and therefore it is simple to use.
  • It underpins the MVC approach to website development, i.e., a good practice philosophy that must be adhered by all developers.
  • Using CodeIgniter, You can construct your own cleaner URI lines.

Sunday, December 11, 2016

How to Calculate Hours Between Two Dates in PHP

Hello Friends,

 Today we bought a new problem which most of the developers in php is finding  is the error of hours difference  between two date. Now as i have seen this error in depth and bought a solution for the same here in my new post.Now get back to the topic many of us face the problem of calculating the hours between two dates and google it for the same to how to solve the problem.

You have to dates and you want to calculate hours between those two dates.

Here is Source code


<?php

$date1 = "2014-05-27 01:00:00";
$date2 = "2014-05-28 02:00:00";
$timestamp1 = strtotime($date1);;
$timestamp2 = strtotime($date2);;
echo "Difference between two dates is ". $hour = abs($timestamp2 - $timestamp1)/(60*60) . " hour(s)";
?>


Here i am taking two variable one is the $date1 and $date2 as you see we have taken the two date and now we are going to calculate the difference of hours between these two dates.

Here we are using the strtotime() function of date and time in php through which we are going to find out hours in two steps.

1. Firstly, convert each date to its equivalent timestamp (as you know, timestamp is number of seconds since January 1 1970 00:00:00 UTC).
2. Secondly, Now the value of timestamp  which we save it  in the two variable such as $timestamp1 and $timestamp2. Now to get the no of Hours we are taking the difference between the two timestamp  variable above as shown in code and divide it by 60*60 to get the no of Hours.


After running the above php code you get the output like as give below.



Output: Difference between two dates is 25 hour(s)














Friday, October 28, 2016

Laravel 5.0 Installation in Xammp server and Also how you can Remove the Public from the Url


Hello friends,
                       Today i am bring with the new installation of Laravel 5.0 on xampp server and also many of you are facing the problem of removing the public/index.php file from the url in Laravel 5.0

There are Various steps you have to follow to install the laravel on your system.

Step - 1:-  Firstly You have to install the Composer on your system from  https://getcomposer.org/
Step-2 :- After This you have to open the command prompt in your system and copy the command in your command prompt as shown below


                                                                       Screenshort-1

After few Seconds you can see your command prompt installing the Laravel files from online url as shown below.
     
 Screenshort-2


After installing the laravel you can go to the xammp folder under htdocs where you can find the folder with the name laravel which you have recently install. You can see the file structure of laravel as given in the screenshort given below.


Screeshort After installing laravel.


 Now when we open our Browser  with the url as http://localhost/laravel/public/index.php  the browser will seen like this.


Browser will show you the window like this
when we install the laravel in xampp server

As you can see in the browser url it show the public and index.php now I am going to tell you how to remove the public and index.php.
You can create the folder name Local in the laravel folder and move all the files  except public folder inside the  local folder as shown  in the Screenshort below.



here you can create the folder name local and
 move all the files inside it without public folder as shown below.



In the Screen short you can see that i have move all the files inside the local folder 

Now  our next step to  move the files from the public folder to the root of the laravel as shown below.




Here we can move all the files  present in the public folder  to the outside as shown above.  but again now we can have to make the change the index.php file as shown in the above screenshort.

Now  we can edit some code in the index.php file which  you file in the root folder as in the screenshort given above now when you 


Screenshort of the index.php file in the root folder


Here you can see the two line of code there are 

require __DIR__.'/../bootstrap/autoload.php
$app= require_once __DIR__.'/../bootstrap/app.php';


replace these two files with the  lines of code give below.

require __DIR__.'/local/bootstrap/autoload.php
$app= require_once __DIR__.'/local/bootstrap/app.php';

You can add the local folder name as shown above after that when you run you laravel in the browser you can see the welcome page like this.


                         
Screenshort of Welcome page of Laravel

Now you can see the url in the Browser  you have successfully remove the public/index.php file from the laravel file. 

If you still find the problem you can view the  video related to installation of laravel on xammp server and also how you can remove the public/index.php file from the laravel url 

























Wednesday, October 5, 2016

Codeigniter Installation on Xammp Server on Windows 7

Hello friends,
                      Today i am bought a new things for you guess what , today i bought you a video tutorials for installing the Codeigniter on Xammp Server . Many of us have problem in installing the codeigniter on Xammp Server on windows 7 platform. In this tutorials you will see how we can install the codeigniter and also how the MVC framework works.. I hope this tutorials work for you especially for beginners Developers.

Thursday, September 29, 2016

Download Latest Version of Codeigniter

Hello friends,
                       I am back again, today i have bought a  technologies named CodeIgniter which is Based on MVC Framework. Many of you have heard about CodeIgniter . it is one of the MVC Framework which is mostly used in Web Developement  such as making the website on the MVC Framework. The website can be developed in many other technologies such as Laravel, Symfony,Cake PHP and many other framework available in the market. but today i am here to talk about the CodeIgniter. CodeIgniter is one of the Framework available in the Market and it is based on MVC Arcitecture. Here MVC stands for three different things but in a one box. In MVC , M  stands for Model, V stands for View and C stands for Controller. The functionality How MVC works i told you in my next post. and also told you how to install a codeigniter on a system. For today you can download a new version of codeigniter which is version- 3.1.0 from download link.

Click below to Download the set up