CodeIgniter From Scratch: Day 1

Leave a Comment

CodeIgniter From Scratch: Day 1

Over the course of about 10 videos, Jeffrey Way will teach you exactly how to use this framework. Ultimately, we'll work our way up to building a custom CMS. Without further ado, here's day one!


How to install laravel on windows xammp server.

Leave a Comment

Watch this video to learn how to install laravel on windows xammp server


How to do form validation in codeigniter

Leave a Comment

Form validation in CodeIgniter using its form validation library

Before explaining CodeIgniter's approach to data validation, let's describe the ideal scenario:
  1. A form is displayed. 
  2. You fill it in and submit it. 
  3. If you submitted something invalid, or perhaps missed a required item, the form is redisplayed containing your data along with an error message describing the problem. 
  4. This process continues until you have submitted a valid form.
In order to implement form validation you'll need three things:
  1. A View file containing a form.
  2. A View file containing a "success" message to be displayed upon successful submission.
  3. A controller function to receive and process the submitted data.
let's start with controller i.e. form_validation.php.


<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class form_validation extends CI_Controller {
 
 function __construct()
 {
  parent::__construct();
  $this->load->library('form_validation');
$this->load->helper('form');
 }

 function index()
 {
  $this->load->view('form_validation');
 }

 function check_validation()
 {
  $this->form_validation->set_rules('name', 'Name', 'trim|required|min_length[5]|xss_clean');
  $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|xss_clean');
  $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[5]|xss_clean|matches[cpassword]');
  $this->form_validation->set_rules('cpassword', 'Confrim password', 'trim|required|min_length[5]|xss_clean');
  $this->form_validation->set_rules('website_url', 'Url', 'trim|required|xss_clean');
  
  if($this->form_validation->run()==true){
   print_r($this->input->post());
  }else{
   $this->load->view('form_validation');
  }
 }
}
Now lets create view file form_validation.php.

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="utf-8">
 <title>Form Validation In CodeIgniter</title>
 <style type="text/css">
 .warpper{
  width: 100%;
 }
 .warpper table{
  margin: 50px auto;
  text-align: center;
 }
 h1{
  text-align: center;
 }
 </style>
</head>
<body>
 <div class="warpper">
  <h1>Form Validation In CodeIgniter</h1>
  <?php echo form_open('form_validation/check_validation');?>
   <table border=1 cellpadding=5 cellspaceing=5>
    <tr>
     <td>Name</td>
     <td>
      <?php echo form_input('name');?>
      <?php echo form_error('name');  ?>
     </td>
    </tr>
    <tr>
     <td>Email Id</td>
     <td>
      <?php echo form_input('email');?>
      <?php echo form_error('email');  ?>
     </td>
    </tr>
    <tr><td>Password</td>
     <td>
      <?php echo form_password('password');?>
      <?php echo form_error('password');  ?>
     </td>
    </tr>
    <tr><td>Confrim password</td>
     <td>
      <?php echo form_password('cpassword');?>
      <?php echo form_error('cpassword');  ?>
     </td>
    </tr>
    <tr><td>website url</td>
     <td>
      <?php echo form_input('website_url');?>
      <?php echo form_error('website_url');  ?>
     </td>
    </tr>
    <tr colspan="2"><td><input type="submit"/></td></tr>
   </table>
  <?php echo  form_close();?>
 </div>
</body>
</html>


Explanation

The form (form_validation.php) is a standard web form with a couple exceptions:
  1. It uses a form helper to create the form opening. Technically, this isn't necessary. You could create the form using standard HTML. However, the benefit of using the helper is that it generates the action URL for you, based on the URL in your config file. This makes your application more portable in the event your URLs change.
  2. Controller has one function: construct() This function initializes the validation class and loads the form helper and load the form_validation library.
  3. Index(): This function loads view file.
  4. Run this code in using http://localhost/ci/form_validation/. You will get below screen.
  5. Now submit the form with the fields blank and you should see the error messages. If you submit the form with all the fields populated you'll see your success page.
  6. Form submitted on the check_validation function this function check various validation rules.If validation is true then i will print all post data else it will return to form will error massage.


Set Validation rules:

CodeIgniter lets you set as many validation rules as you need for a given field, cascading them in order, and it even lets you prep and pre-process the field data at the same time. To set validation rules you will use the set_rules() function:

$this->form_validation->set_rules();


The above function takes three parameters as input:

  1. The field name - the exact name you've given the form field.
  2. A "human" name for this field, which will be inserted into the error message. For example, if your field is named "user" you might give it a human name of "Username". Note: If you would like the field name to be stored in a language file.
  3. The validation rules for this form field.

Some validation rules are here.
  • trim : This remove space from string both side(left and right).
  • required : Fields are compulsory.
  • min_length : Minimum length of the field is 5 character.
  • xss_clean : This removes malicious data.
  • valid_email : This will check user enter valid email or not.
  • matches : This will match one value to anotoher.
For more validation rule visit this link.   After all this if you submit your form then it will look like this



It's not look well so let's do some css to validation error.Modify check_validation function

function check_validation()
 {
  $this->form_validation->set_rules('name', 'Name', 'trim|required|min_length[5]|xss_clean');
  $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|xss_clean');
  $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[5]|xss_clean|matches[cpassword]');
  $this->form_validation->set_rules('cpassword', 'Confrim password', 'trim|required|min_length[5]|xss_clean');
  $this->form_validation->set_rules('website_url', 'Url', 'trim|required|xss_clean');
  $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); // added new line
  if($this->form_validation->run()==true){
   print_r($this->input->post());
  }else{
   $this->load->view('form_validation');
  }
 }

Modify view file also add some css to file
<style type="text/css">
 .warpper{
  width: 100%;
 }
 .warpper table{
  margin: 50px auto;
  text-align: center;
 }
 h1{
  text-align: center;
 }
 .error{
  color: red;
 }
 </style>

After that if you submit the form then you will get screen like this screenshot.

Now its look little bit nice.If you inspect element those error then you get <div> with class error.

Changing the Error Delimiters: By default, the Form Validation class adds a paragraph tag (<p>) around each error message shown. You can either change these delimiters globally or individually.

  1. Changing delimiters Globally

    To globally change the error delimiters, in your controller function, just after loading the Form Validation class, add this:
    $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
    

    In this example, we've switched to using div tags.
  2. Changing delimiters Individually

    If you want to change error delimiter individually then you do this in view file when you write your form_error().
    <?php echo form_error('field name', '<div class="error">', '</div>'); ?>
    


    or

    from_error is used to show error individually.If you want to show all error at one place then you can use validation_errors().
    <?php echo validation_errors('<div class="error">', '</div>'); ?>
    

    If you want to use validation_errors() then you have to change your view file like this.

    <!DOCTYPE html>
    <html lang="en">
    <head>
     <meta charset="utf-8">
     <title>Form Validation In CodeIgniter</title>
     <style type="text/css">
     .warpper{
      width: 100%;
     }
     .warpper table{
      margin: 50px auto;
      text-align: center;
     }
     h1{
      text-align: center;
     }
     .error{
      color: red;
     }
     </style>
    </head>
    <body>
     <div class="warpper">
      <h1>Form Validation In CodeIgniter</h1>
      <?php echo form_open('form_validation/check_validation');?>
       <table border=1 cellpadding=5 cellspaceing=5>
        <tr>
         <td></td>
         <td>
          <?php echo validation_errors(); ?>
         </td>
        </tr>
        <tr>
         <td>Name</td>
         <td>
          <?php echo form_input('name');?>
         </td>
        </tr>
        <tr>
         <td>Email Id</td>
         <td>
          <?php echo form_input('email');?>
         </td>
        </tr>
        <tr><td>Password</td>
         <td>
          <?php echo form_password('password');?>
         </td>
        </tr>
        <tr><td>Confrim password</td>
         <td>
          <?php echo form_password('cpassword');?>
         </td>
        </tr>
        <tr><td>website url</td>
         <td>
          <?php echo form_input('website_url');?>
         </td>
        </tr>
        <tr colspan="2"><td><input type="submit"/></td></tr>
       </table>
      <?php echo  form_close();?>
     </div>
    </body>
    </html>
    
    
    After changing the view file if you submit form then it's show error like below image.

    error
If you submit your form using this value.

error


And submit form then it will accept all value and it's shows output like this :

error


but if you check that website url is wrong but it's accepted that value then how to handle this type of situation.No worries to handle this type of situation codeigniter introduce it's callback method.

Callbacks: Your own Validation Functions
The validation system supports callbacks to your own validation functions. This permits you to extend the validation class to meet your needs. For example, here we need to handle website url.so we modify the check_validation function.
function check_validation()
 {
  $this->form_validation->set_rules('name', 'Name', 'trim|required|min_length[5]|xss_clean');
  $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|xss_clean');
  $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[5]|xss_clean|matches[cpassword]');
  $this->form_validation->set_rules('cpassword', 'Confrim password', 'trim|required|min_length[5]|xss_clean');
  $this->form_validation->set_rules('website_url', 'Url', 'trim|required|xss_clean|callback_checkwebsiteurl'); //modify this line
  $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
  if($this->form_validation->run()==true){
   echo "<pre>";
   print_r($this->input->post());
  }else{
   $this->load->view('form_validation');
  }
 }
Add new function in your controller file i.e form_validation.php
function checkwebsiteurl($string_url)
 {
        $reg_exp = "@^(http\:\/\/|https\:\/\/)?([a-z0-9][a-z0-9\-]*\.)+[a-z0-9][a-z0-9\-]*$@i";
        if(preg_match($reg_exp, $string_url) == TRUE){
         return TRUE;
        }
        else{
         $this->form_validation->set_message('checkwebsiteurl', 'URL is invalid format');
         return FALSE;
        }
 }

Reload your form and submit it with url mohit jain.You can see that the form field data was passed to your callback function for you to process.
To invoke a callback just put the function name in a rule, with "callback_" as the rule prefix. If you need to receive an extra parameter in your callback function, just add it normally after the function name between square brackets, as in: "callback_foo[bar]", then it will be passed as the second argument of your callback function.
Note: You can also process the form data that is passed to your callback and return it. If your callback returns anything other than a boolean TRUE/FALSE it is assumed that the data is your newly processed form data.

Setting Error Messages


All of the native error messages are located in the following language file: language/english/form_validation_lang.php.
To set your own custom message you can either edit that file, or use the following function:

$this->form_validation->set_message('rule', 'Error Message');

Where rule corresponds to the name of a particular rule, and Error Message is the text you would like displayed.
If you include %s in your error string, it will be replaced with the "human" name you used for your field when you set your rules.
In the "callback" example above, the error message was set by passing the name of the function:
$this->form_validation->set_message('checkwebsiteurl', 'URL is invalid format');


Re-populating the form


Thus far we have only been dealing with errors. It's time to repopulate the form field with the submitted data. CodeIgniter offers several helper functions that permit you to do this.We need to change our view file to implement this function
<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="utf-8">
 <title>Form Validation In CodeIgniter</title>
 <style type="text/css">
 .warpper{
  width: 100%;
 }
 .warpper table{
  margin: 50px auto;
  text-align: center;
 }
 h1{
  text-align: center;
 }
 .error{
  color: red;
 }
 </style>
</head>
<body>
 <div class="warpper">
  <h1>Form Validation In CodeIgniter</h1>
  <?php echo form_open('form_validation/check_validation');?>
   <table border=1 cellpadding=5 cellspaceing=5>
    <tr>
     <td>Name</td>
     <td>
      <?php echo form_input('name',set_value('name'));?>
      <?php echo form_error('name');  ?>
     </td>
    </tr>
    <tr>
     <td>Email Id</td>
     <td>
      <?php echo form_input('email',set_value('email'));?>
      <?php echo form_error('email');  ?>
     </td>
    </tr>
    <tr><td>Password</td>
     <td>
      <?php echo form_password('password',set_value('password'));?>
      <?php echo form_error('password');  ?>
     </td>
    </tr>
    <tr><td>Confrim password</td>
     <td>
      <?php echo form_password('cpassword',set_value('cpassword'));?>
      <?php echo form_error('cpassword');  ?>
     </td>
    </tr>
    <tr><td>website url</td>
     <td>
      <?php echo form_input('website_url',set_value('website_url'));?>
      <?php echo form_error('website_url');  ?>
     </td>
    </tr>
    <tr colspan="2"><td><input type="submit"/></td></tr>
   </table>
  <?php echo  form_close();?>
 </div>
</body>
</html>

Now reload your page and submit the form so that it triggers an error. Your form fields should now be re-populated.
We use set_value('field name') to re-populating the form.If we enter only website url wrong and submit then its look like this screenshot.All value are automatically re-populating the form.





Helpful links




Please comment down below if you have any query and please follows us for more awesome tutorials and keep motivating us .

How to set cookie in codeigniter

Leave a Comment

Cookies in codeigniter



To use cookies in codeigniter we have to use its helper class.The Cookie Helper file contains functions that assist in working with cookies.
Below is the example to set cookies in get its values.So we create controller cookies_demo.php.Add the some method like the below example:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class cookies_demo extends CI_Controller {
 
 function __construct()
 {
  parent::__construct();
  $this->load->helper('cookie');
 }
 // to set cookies 
 function set()
 {
  $cookie= array(
      'name'   => 'demo',
      'value'  => 'Hello i m cookies which saved in this broswer',
       'expire' => '86500',
  );
  $this->input->set_cookie($cookie);
  echo "cookies successfully set";
 }
 // to get cookies
 function get()
 {
  echo $this->input->cookie('demo',true);
 }
}



Loading this Helper
This helper is loaded using the following code:
$this->load->helper('cookie');


The following functions are available:

$this->input->set_cookie()

Sets a cookie containing the values you specify. There are two ways to pass information to this function so that a cookie can be set: Array Method, and Discrete Parameters:

Array Method



Using this method, an associative array is passed to the first parameter:
$cookie = array(
    'name'   => 'demo',
      'value'  => 'Hello i m cookies which saved in this broswer',
       'expire' => '86500',
    'domain' => '.only4ututorials.blogspot.com',
    'path'   => '/',
    'prefix' => 'myprefix_',
    'secure' => TRUE
);

$this->input->set_cookie($cookie);


Notes:

  • Only the name and value are required. To delete a cookie set it with the expiration blank.
  • The expiration is set in seconds, which will be added to the current time. Do not include the time, but rather only the number of seconds from now that you wish the cookie to be valid. If the expiration is set to zero the cookie will only last as long as the browser is open.
  • For site-wide cookies regardless of how your site is requested, add your URL to the domain starting with a period, like this: .your-domain.com
  • The path is usually not needed since the function sets a root path.
  • The prefix is only needed if you need to avoid name collisions with other identically named cookies for your server.
  • The secure boolean is only needed if you want to make it a secure cookie by setting it to TRUE.
If after all this your cookies not set.Then check belows Points.

  • If you set 'secure' => TRUE.  which is only for https.
  • Always try to set 'expire' => 'something'.


Discrete Parameters
If you prefer, you can set the cookie by passing data using individual parameters:
$this->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure);



$this->input->cookie()
Lets you fetch a cookie. The first parameter will contain the name of the cookie you are looking for (including any prefixes):
$this->input->cookie('demo',true);

The function returns FALSE (boolean) if the item you are attempting to retrieve does not exist. The second optional parameter lets you run the data through the XSS filter. It's enabled by setting the second parameter to boolean TRUE;



Helpful links




Please comment down below if you have any query and please follows us for more awesome tutorials and keep motivating us .

CodeIgniter From Scratch : Select records from database

Leave a Comment

Select records from database for CodeIgniter CRUD



In previous tutorials we learn how to set up out project directory for codeigniter crud.In this we learn how to fetch data from database using MVC of codegniter.
Let's go to our controller i.e. data.php and add some stuff to make CRUD work. Add the some method like the below example:


<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class data extends CI_Controller {
 
 function __construct()
 {
  parent::__construct();
  //load the  model
  $this->load->model('mdl_data');
 }
 // load the view and fetch data from out model function
 public function index()
 {
  $arrData['users'] = $this->mdl_data->getall(); //call the mdl_data getall function to getall data
  $this->load->view('show',$arrData); // pass all data to view
 }
}



Now let's create out model file which place inside application/model/ name as mdl_data.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Mdl_data extends CI_Model {

 function __construct()
 {
  parent::__construct();
 }
 
 function getall(){
  $query =$this->db->get('users'); //users is the table name
  if($query->num_rows()>0){
   return $query->result_array();  // this will return all data into array
  }
 }
}
Now let's create our view The results that we have seen we can use them to have Codeigniter CRUD. We just need a view to do it. So a view will look like this:
<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="utf-8">
 <title>CRUD In CodeIgniter</title>
 <style type="text/css">
 .warpper{
  width: 100%;
 }
 .warpper table{
  margin: 50px auto;
  text-align: center;
 }
 .warpper p{
  margin: 50px auto;
 }
 h1{
  text-align: center;
 }
 </style>
</head>
<body>
 <div class="warpper">
  <h1>CRUD In CI</h1>
  <?php if($this->session->flashdata('success')){ ?> 
   <p style="color:green"><?php echo $this->session->flashdata('success'); ?></p>
  <?php } ?>
  <table border=1 cellpadding=5 cellspaceing=5>
   <tr colspan="6"><td><a href="<?php echo base_url()."data/add/"; ?>">Add New Record</a></td></tr>
   <tr>
    <th>Id</th>
    <th>Name</th>
    <th>Email Id</th>
    <th>Edit</th>
    <th>Delete</th>
   </tr>
   <?php if($users) { foreach ($users as $user) { ?>
   <tr>
    <td><?php echo $user['id']; ?></td>
    <td><?php echo $user['name']; ?></td>
    <td><?php echo $user['email_id']; ?></td>
    <th><a href="<?php echo base_url()."data/edit/".$user['id']; ?>">Edit</a></th>
    <th><a href="<?php echo base_url()."data/delete/".$user['id']; ?>">Delete</a></th>
   </tr>
   <?php } } ?>
  </table>
 </div>
</body>
</html>



After doing all this run the code like this http://localhost/crud/data/.So a it will look like this:



CodeIgniter From Scratch : Directory Setup for CRUD

Leave a Comment

Directory Setup And Database Setup For CodeIgniter CRUD.


Step 1: Download Codeigniter and check this Link to set up codeigniter
After Proper Setup Your Page get look like this as seen below



Step 2: Now we are ready to configure our database for our codeigniter project.To do that goto your codeigniter /appication/config/database.php.Open that file in your editor it will look like this.
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| DATABASE CONNECTIVITY SETTINGS
| -------------------------------------------------------------------
| This file will contain the settings needed to access your database.
|
| For complete instructions please consult the 'Database Connection'
| page of the User Guide.
|
| -------------------------------------------------------------------
| EXPLANATION OF VARIABLES
| -------------------------------------------------------------------
|
| ['hostname'] The hostname of your database server.
| ['username'] The username used to connect to the database
| ['password'] The password used to connect to the database
| ['database'] The name of the database you want to connect to
| ['dbdriver'] The database type. ie: mysql.  Currently supported:
     mysql, mysqli, postgre, odbc, mssql, sqlite, oci8
| ['dbprefix'] You can add an optional prefix, which will be added
|     to the table name when using the  Active Record class
| ['pconnect'] TRUE/FALSE - Whether to use a persistent connection
| ['db_debug'] TRUE/FALSE - Whether database errors should be displayed.
| ['cache_on'] TRUE/FALSE - Enables/disables query caching
| ['cachedir'] The path to the folder where cache files should be stored
| ['char_set'] The character set used in communicating with the database
| ['dbcollat'] The character collation used in communicating with the database
|     NOTE: For MySQL and MySQLi databases, this setting is only used
|      as a backup if your server is running PHP < 5.2.3 or MySQL < 5.0.7
|     (and in table creation queries made with DB Forge).
|      There is an incompatibility in PHP with mysql_real_escape_string() which
|      can make your site vulnerable to SQL injection if you are using a
|      multi-byte character set and are running versions lower than these.
|      Sites using Latin-1 or UTF-8 database character set and collation are unaffected.
| ['swap_pre'] A default table prefix that should be swapped with the dbprefix
| ['autoinit'] Whether or not to automatically initialize the database.
| ['stricton'] TRUE/FALSE - forces 'Strict Mode' connections
|       - good for ensuring strict SQL while developing
|
| The $active_group variable lets you choose which connection group to
| make active.  By default there is only one group (the 'default' group).
|
| The $active_record variables lets you determine whether or not to load
| the active record class
*/

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = '';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;


/* End of file database.php */
/* Location: ./application/config/database.php */


you have change some filed i.e
$db['default']['hostname'] = 'localhost';  // change it with your host name
$db['default']['username'] = 'root';       // change it with your username
$db['default']['password'] = 'root';       // change it with your password
$db['default']['database'] = 'crud_database'; // change it with your DB name
$db['default']['dbdriver'] = 'mysql';                   


After that goto your mysql server phpmyadmin create a new database using this query
Create Database crud_database;     // change it with your database name


Create your table in your database. Let's say we have the table with table name users. The SQL code that you can insert is:
CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `email_id` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`id`, `name`, `email_id`) VALUES
(1, 'mohit jain', 'mohitj475@gmai.com');
Let's go to the next step.

Step 3: Setup directory for the our CodeIgniter CRUD.

Step 4: Open the autoload.php file i.e. in application/config/autoload.php.

/*
| -------------------------------------------------------------------
|  Auto-load Libraries
| -------------------------------------------------------------------
| These are the classes located in the system/libraries folder
| or in your application/libraries folder.
|
| Prototype:
|
|	$autoload['libraries'] = array('database', 'session', 'xmlrpc');
*/

$autoload['libraries'] = array('database','session');


/*
| -------------------------------------------------------------------
|  Auto-load Helper Files
| -------------------------------------------------------------------
| Prototype:
|
|	$autoload['helper'] = array('url', 'file');
*/

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


Autoload the our libraries and helper which we use in this Codeigniter crud.

How to send mail using CodeIgniter and smtp

Leave a Comment

Send mail using codeIgniter and smtp



Sending email is not only simple, but you can configure it on the fly or set your preferences in a config file.In the past, I have used the email helper extensively in combination with sendmail, however for a new project I was required to route e-mail through a third-party SMTP server, in this case Gmail. I used the following code:
 function sendMail()
 {
     $config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'xxx@gmail.com', // change it to yours
    'smtp_pass' => 'xxx', // change it to yours
    'mailtype' => 'html',
    'charset' => 'iso-8859-1',
    'wordwrap' => TRUE
  );

       $message = '';
       $this->load->library('email', $config);
       $this->email->set_newline("\r\n");  
       $this->email->from('xxx@gmail.com'); // change it to yours
       $this->email->to('xxx@gmail.com');// change it to yours
       $this->email->subject('CodeIgniter and smtp');
       $this->email->message('send mail using CodeIgniter and smtp');
     if($this->email->send())
     {
       echo 'Email sent.';
     }
     else
     {
      show_error($this->email->print_debugger());
     }

 }







Helpful links


How to send mail using CodeIgniter.

Leave a Comment

Send E-mail using codeIgniter.


Sending email is not only simple, but you can configure it on the fly or set your preferences in a config file. CodeIgniter's Email Class supports the following features:

  • Multiple Protocols: 
  • Mail, Sendmail, and SMTP Multiple recipients 
  • CC and BCCs 
  • HTML or Plaintext email 
  • Attachments 
  • Word wrapping 
  • Priorities 
  • BCC Batch Mode, enabling large email lists to be broken into small BCC batches. 
  • Email Debugging tools
Here is a basic example demonstrating how you might send HTML email.
So let's start with controller.

Controller Name : email.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Email extends CI_Controller {
 
 function __construct(){

  parent::__construct();
  //load the  library
  $this->load->library('email');
 }

 function send_mail(){
 
  $this->email->from('mohitj475@gmail.com', 'Mohit');
  $this->email->to('mohitj475@gmail.com');
  
  $this->email->subject('mail send demonstration');
  $this->email->message('this is testing');
  
  $this->email->send();
  
  echo $this->email->print_debugger();
 }
}



If you run above code then you will get output like this




Explanation : In controller's constructor method first we load email library so we can use library function.After that we created send_mail function in to we use library function.

Email Function Reference


$this->email->from()

Sets the email address and name of the person sending the email:
$this->email->from('mohitj475@gmail.com', 'Mohit');
$this->email->to()

Sets the email address(s) of the recipient(s). Can be a single email, a comma-delimited list or an array:
$this->email->to('mohitj475@gmail.com');
$this->email->to('one@example.com, two@example.com, three@example.com');
$list = array('one@example.com', 'two@example.com', 'three@example.com');

$this->email->to($list);
$this->email->subject()

Sets the email subject:
$this->email->subject('mail send demonstration');
$this->email->message()

Sets the email message body:
 $this->email->message('this is testing');
$this->email->send()

The Email sending function. Returns boolean TRUE or FALSE based on success or failure, enabling it to be used conditionally:
if ( ! $this->email->send())
{
    // Generate error
}
For function more Visit this link





Helpful links


CodeIgniter From Scratch : CRUD

Leave a Comment

Basic CRUD With Codeigniter



If you are totally new to the codeigniter experience and you can't still understand the way that you can create a CRUD, this codeigniter CRUD tutorial is just for you.We'll review how to easily create, read, update, and delete records using CI's active-records class.

So, We will do it this process in 4 stage

Stage 1 : In this stage we will setup a directory and database.

Stage 2 : In this stage we will Select all database from the database and show into the view.

Stage 3 : In this stage we will Edit and Update Data from the database

Stage 4 : In this stage we will see how to delete data from the database

let's start with Stage 1

How to Setup CodeIgniter on local xampp server with screenshots

Leave a Comment

Codelgniter install Step By Step Tutorial for beginners:

What is CodeIgniter?

CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. If you're a developer who lives in the real world of shared hosting accounts and clients with deadlines, and if you're tired of ponderously large and thoroughly undocumented frameworks, then CodeIgniter might be a good fit.

How To install CodeIgniter?

In our local server with step by step with screenshots.

Step 1 : Download codeIgniter from Here

Step 2 : After downloaded codelgniter extract in your server root directory i.e. your htdocs folder

Step 3 : After that rename that folder into your project name In my case its folder name is CI you can rename whatever you want

Step 4 : After that open your browser and run http://localhost/CI/

Your Page get look like this as seen below



And here you done your codelgniter is finally setup Now you start with its coding...enjoy...





Helpful links


How To Create Captcha With Codeigniter

Leave a Comment
In this tutorial I will show you how to use the the codeigniter captcha helper.

The CAPTCHA Helper file contains functions that assist in creating CAPTCHA images.

Frist we have load library of captcha in controller.

$this->load->helper('captcha');
Now we will create controller for the CAPTCHA so let's start.Before we create controller we will create captcha folder in root directory of project.



<?php
/**
* 
*/
class Captcha extends CI_Controller
{
 
 function __construct()
 {
  parent::__construct();
  $this->load->helper('captcha');
  $this->load->helper('url');
 }

 function index()
 {
  $vals = array(
      'img_path'  => './captcha/',
     'img_url'  => base_url().'/captcha/',
     'img_width' => 150,
     'img_height' => '50',
     'expiration' => 7200
     );

 $cap = create_captcha($vals);
 print_r($cap['word']);
 echo $cap['image'];
 }
}

?>
EXPLANATION : 1) In construct method of the controller we load captcha library for the captcha and url library for the base_url()
2) In Index method we create array of captcha.
3) Only the img_path and img_url are required.Other are optional.
4) The "captcha" folder must be writable (666, or 777).
5) The "expiration" (in seconds) signifies how long an image will remain in the captcha folder before it will be deleted. The default is two hours.
So that's it we create captcha for us.Our captcha look like this.



print_r($cap['word']); will print the word which is in captcha image we can use this word for the checking user is enter wrong value or right.

echo $cap['image']; will for the image which is shown as captcha.
If we look in captcha folder the image is store in that folder.



Helpful links


Pagination With Codeigniter

Leave a Comment
Hello Guy's,

Pagination is particularly useful when you are coding an application that interfaces with a database. A large dataset might have hundreds of possible results for one query, and pagination creates a much nicer user experience.
In this tutorial, I’ll use CodeIgniter’s pagination library to show you how you can create a paginated list of results from a MySQL database. Along the way, you’ll also see how to fix a problem with the pagination links that the library might produce.
I’ll assume you have an installation of CodeIgniter And you already ready with removing index.php from URL.
If yes then well and good otherwise you can check this tutorials How To Remove Index.php From url
let's Start Creating file in folder

After that create database test and get sql table country from Here
Let's Start with Model i.e mdl_pagination.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Mdl_pagination extends CI_Model {

 function __construct(){
  parent::__construct();
 }

 function countcountry(){
  $query = $this->db->get('countries');
  return $query->num_rows();           // return total number of country
 }

 function getcountries($limit,$offset){
  $query = $this->db->get('countries',$limit,$offset);
  return $query->result_array();           // return the country 
 }

}


In Controller i.e pagination.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Pagination extends CI_Controller {

 function __construct(){
  parent::__construct();
  $this->load->model('mdl_pagination');
  $this->load->library('table');
  $this->load->helper("url");
 }

 public function country($offset=null)
 {
  $this->load->library('pagination');

  $config['base_url'] = 'http://localhost/ci/pagination/country/';    // url of the page
  $config['total_rows'] = $this->mdl_pagination->countcountry(); //get total number of records 
  $config['per_page'] = 20;  // define how many records on page

  $this->pagination->initialize($config);

  $data['country'] = $this->mdl_pagination->getcountries($config['per_page'],$offset);
  $this->load->view('pagination',$data);
 }

}

In View i.e Pagination.php
<html>
<body>
 <div id="container">
  <h1>Countries</h1>
  <div id="body">
 <?php
 $this->table->set_heading('id', 'code', 'name');
 echo $this->table->generate($country);
 echo $this->pagination->create_links();
 ?>
  </div>
 </div>
</body>
</html>


Explanation: Run the page in browser with url http://localhost/ci/pagination/country
In url ci is the name of project, pagination is the name of controller after the last parameter is the name of function which is written in the controller of pagination.


When we call the country function after hitting the url in browser then first the __construct method execute from the pagination controller class it's load the model, table library, url helper and pagination library then it call the country method.In country method first we set the config of the pagination class $config['base_url'] which mean which url is called for the pagination after that how many records we have to fetch that all records we have to call the mdl_pagination which is our model class then we have set how much records we have to show in per_page.
$config['base_url'] = 'http://localhost/ci/pagination/country/';
$config['total_rows'] = $this->mdl_pagination->countcountry();
$config['per_page'] = 20;

we can also also write dynamic base_url like this
$config['base_url'] = base_url().'pagination/country/';

The base_url() function get url which is define in your config.php
$config['base_url'] = 'http://localhost/ci/';

Then we load the config or initialize config by using $this->pagination->initialize($config);. After that we fetch country data from country table using getcountries method of mdl_pagination class of model. We passed two arguments to this function $config['per_page '] as its limit then $offset as its offset of query.

First time when we load page then $config['per_page '] is 20 and $offset is null then its shows first 20 records from the table after than when we click on the next link then url change in to http://localhost/ci/pagination/country/20 then this time the value for the for the $config['per_page '] is 20 and $offset changes from null to 20. It will take 20 from the url which passed as argument in url after country method this time query will take next 20 records after leaving first 20 which is show.After that we fetch all data in $data['country'] and we pass all data in view

In View first we set heading of the table then we generate the table using echo $this->table->generate($country);.The table class which we loaded in __construct method of the controller class it calls the generate method of its by passing the $country array as argument. This generate method create the table of us with value passed as array.

That's it your pagination is ready it will look like this



we can add extra attributes in config like this
$config['next_link'] = ' >> ';
$config['prev_link'] = ' << ';
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$config['full_tag_open'] = '<p>';
$config['full_tag_close'] = '</p>';
If any error occurs then leave comment after this tutorials we will discuss about that error thank you. If you want to do pagination with ajax you check here.
video tutorials

How to increase website traffics or improve alexa rank

Leave a Comment

Somedays before i read awesome blog which is about how to increase website traffic and improve alexa rank and i want say thank you to this author who give me such a great information about website traffic and improve alexa rank so i just thought share this blog with you here it is


Alexa Boostup





Nowadays webmasters are keeping their eye on Alexa ranks of their blog this may be due to the delay in the page rank update from google or due to the increasing importance of Alexa rank among guest bloggers. Today am here with an awesome trick which helps you to boost your Alexa rankings. First of all let me tell you this is a black hat method named as Alexa Autosurfing. Since it's a blackhat method I personally never used it but it seems to be a working trick. Boosting up Alexa rank is quite difficult if you are sticking to the legit ways. So check out this awesome method for Alexa boost up.



Alexa Autosurf

A Brilliant Way To Boost Alexa Rank.It works like this "1 View = 1 Point." Additional points are awarded for referring others to autosurf. Let's check out it's working of Autosurf.




How Its Works

Basically Alexa Autosurf is a traffic exchange site in which you could exchange a points in return to visitors. to gain points you should visit a blog and stay there for at least 50 seconds. Easiest way to get points in bulk is by referring the website. Refer your friends to Alexa autosurf and gain 1000 points for each refer.


Google Adsense And Autosurf

Are you planning to run autosurf on an adsense enabled blog? then you are inviting trouble to your blog. Google policies clearly says that it hate traffic exchange programs. Nowadays google is quite strict in its policies any small violations of the policies may lead to banning of the account.


Conclusion

Alexa autosurf improves your Alexa rank but it makes your blog vulnerable to adsense ban. Thinks twice before using this method of boosting up Alexa rank.


For more information Click Here

How To Remove Index.php From CodeIgniter in Windows Xampp

Leave a Comment

Remove Index.php From CodeIgniter

Follow This Step
1. First check mod_rewrite is enabled or not
2. To check this create php file type in that
    
  <?php
     phpinfo();
  ?>
 
3. Run into broswer

4. Search for the mod_rewrite if you will find that in loaded module then its enabled else you have to enabled this mod_rewrite check this tutorials for enable mod_rewrite
5. After that create .htaccess file in your root folder of codeigniter
6. Copy this below codeand paste into that .htaccess file
  RewriteEngine On
  RewriteCond $1 !^(index\.php|resources|robots\.txt)
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L,QSA]
 
7. After that change into the config.php of codeigniter
  $config['index_page'] = 'index.php';
  to 
  $config['index_page'] = ' ';
 

8. Here you done now run the file with index.php using url http://localhost/ci/welcome
   Enjoy.......:)
Any problem then comment below

You Can Watch Video Here


Helpful links


How to enable mod_rewrite in apache2
How to enable mod_rewrite in xammp windows


Please comment down below if you have any query and please follows us for more awesome tutorials and keep motivating us .

How to delete facebook page

Leave a Comment

You can watch direct video here is video


How To increase Facebook likes,YouTube Video Likes All social promotion

1 comment

How to increase facebook likes youtube likes ?????



Hello guys Today we will discuss about how to increase facebook like youtube likes this tutorial will teach you how to do that
  1. You have to follow some steps
  2. Here is the secret
  3. Click on this link FREE Social Promotion
  4. Login on website fill all the information to create account
  5. After that click on this button

  6. You can redirect another page fill that page information
  7. From dropdown select what you want to promote fill the necessary information
  8. Finally you done to promote your page on social networking
  9. But if want that your page get more and more promote then you also have to like,share and other thing with another user's pages then you will get points for it
  10. More points more you can promote your pages or videos

You can watch the video to how its works!!!!


How To Install Ubuntu In Windows

Leave a Comment

In this tutorial you can leran how to intall ubuntu in windows machine


How To Install Laravel on Ubuntu

Leave a Comment

Introduction

Laravel is a framework for websites in the PHP programming language. It allows developers to rapidly develop a website by abstracting common tasks used in most web projects, such as authentication, sessions, and caching. Laravel 4, the newest version of Laravel is based on an older framework called Symfony, but with a more expressive syntax

Step by Step Laravel Install as follows:

For Users Who Recently Installed LAMP Stack (Linux, Apache, Mysql, PHP) Please install these before proceeding:

Preparing the server / environment

Log in into your Ubuntu 12.04 admin and update and upgrade Ubuntu:
sudo apt-get update
sudo apt-get upgrade

Choosing the right PHP version

IF You Want: Preparation of installing PHP 5.4: This can be skipped if you are Ok with 5.3. Version
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php5-oldstable
sudo apt-get update
sudo apt-cache policy php5

Installing LAMP if you not install


sudo apt-get install apache2
sudo apt-get install php5
sudo apt-get install mysql-server
sudo apt-get install php5-mysql

Installing PHP extensions


sudo apt-get install unzip
sudo apt-get install curl
sudo apt-get install openssl
sudo apt-get install php5-mcrypt
Usually these above 4 command not installed,but they are necessary to 1.) unzip uesd for the unzip laravel, 2.) use Composer use curl 3.) use Composer also use openssl 4.) use Laravel 4 (which needs mcrypt).

Enable Apache mod_rewrite

Apache mod_write module should be enabled in order to use laravel pretty URL’s. So activate the module by typing this in terminal
sudo a2enmod rewrite

Restart apache


sudo a2enmod rewrite


Install Laravel 4


cd /var/www

composer global require "laravel/installer=~1.1"

composer create-project laravel/laravel --prefer-dist

chmod -R 0777 laravel/app/storage/
Type url in browser http://localhost/laravel/public/
you will see laravel homepage saying 500 Internal server error. To solve the error go to terminal and run this command
sudo nano /etc/apache2/sites-enabled/000-default.conf

Paste this code in that file
<Directory /var/www/> 
  Options Indexes FollowSymLinks MultiViews 
  # changed from None to All 
  AllowOverride All 
  Order allow,deny 
  allow from all 
</Directory> And save that file restart apache using sudo service apache2 restart After that again hit this url http://localhost/laravel/public/ you will get You have arrived.

Get more laravel or other tutorial here

If This help you Please Comment

Helpful links


Powered by Blogger.