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

Codeigniter Ajax dropdown

Codeigniter Ajax dropdown


Codeigniter ajax dropdown Codeigniter Framework Lot of task previously discussed. Today discussed Codeigniter dropdown ajax how to implemented. Similarly Codeigniter ajax Pagination  
Codeigniter Ajax dropdown
Codeigniter Ajax dropdown

Dropdown City and Country Used Ajax


Controller
<?php

class User extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('country_model');
    }

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

    public function register() {
        $data['countries'] = $this->country_model->get_countries();
        $this->load->view('post_view', $data);
    }

    public function get_cities($country) {
        $this->load->model('city_model');
        header('Content-Type: application/x-json; charset=utf-8');
        echo(json_encode($this->city_model->get_cities($country)));
    }

}
City_Model
<?php

class City_model extends CI_Model {

    public function __construct() {
        $this->load->database();
    }

    function get_cities($country = null) {
        $this->db->select('id, city_name');

        if ($country != NULL) {
            $this->db->where('country_id', $country);
        }

        $query = $this->db->get('cities');
        $cities = array();

        if ($query->result()) {
            foreach ($query->result() as $city) {
                $cities[$city->id] = $city->city_name;
            }
            return $cities;
        } else {
            return FALSE;
        }
    }

}
?>

Country_Model

<?php

class Country_model extends CI_Model {

    public function __construct() {
        $this->load->database();
    }

    function get_countries() {
        $this->db->select('id, country_name');
        $query = $this->db->get('countries');
        echo "countries";
        $countries = array();

        if ($query->result()) {
            foreach ($query->result() as $country) {
                $countries[$country->id] = $country->country_name;
            }
            return $countries;
        } else {
            return FALSE;
        }
    }

}
?>

View
   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script type="text/javascript">// <![CDATA[
            $(document).ready(function() {
                $('#country').change(function() { //any select change on the dropdown with id country trigger this code
                    $("#cities > option").remove(); //first of all clear select items
                    var country_id = $('#country').val(); // here we are taking country id of the selected one.
                    $.ajax({
                        type: "POST",
                        url: "http://localhost/task/user/get_cities/" + country_id, //here we are calling our user controller and get_cities method with the country_id

                        success: function(cities) //we're calling the response json array 'cities'
                        {
                            $.each(cities, function(id, city) //here we're doing a foeach loop round each city with id as the key and city as the value
                            {
                                var opt = $('<option />'); // here we're creating a new select option with for each city
                                opt.val(id);
                                opt.text(city);
                                $('#cities').append(opt); //here we will append these new select options to a dropdown with the id 'cities'
                            });
                        }

                    });

                });
            });
            // ]]>
        </script>
    </head>
    <body>
        <?php $countries['#'] = 'Please Select'; ?>

        <label for="country">Country: </label><?php echo form_dropdown('country_id', $countries, '#', 'id="country"'); ?><br />
        <?php $cities['#'] = 'Please Select'; ?>
        <label for="city">City: </label><?php echo form_dropdown('city_id', $cities, '#', 'id="cities"'); ?><br />
    </body>
</html>


Codeigniter Frameworks

Codeigniter Frameworks

Codeigniter Frameworks is a powerful PHP Frameworks with a very small footprint, built for developer and very easily learn in Codeigniter Frameworks. Basic Introduction of Codeigniter Framework  Please Click Here   

Codeigniter Frameworks
Codeigniter Frameworks


Best Features of Codegniter

  • Model-View-Controller System(MVC)
  • Light Wight
  • Full Featured database classes with support for several platforms
  • Form and Data Validation
  • Active Record Databasupport
  • FTP Class
  • Session Management
  • Security and XSS Filtering
  • Email Sending Class. Support Attachments, HTML/Text email, and Multiple Protocols
  • Localization
  • Pagination and Image manipulation LibraryC
  • Search Engine Friendly URL's
Codeigniter Session Storage

Codeigniter Session Storage is very simpley and easily storage Login Authentication Username storage session Read More

Important Codeigniter Tutorial


Security Features of Codeigniter Frameworks 

1.Codeigniter Seacurity Features First Remote code Execution <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?> This Ensures that the PHP Files is not accessible directly by manipulating or running a script, which would compromise the system.

2.SQL injection: This type of attack is highly common on the web. A SQL injection occurs when an attacker exploits the front-end and the post data to retrieve secure data from the database. According to CodeIgniter manual, it becomes evident that your web application is automatically safe from SQL injection as the POST data is retrieved in the controller using $this->input->post (‘’); which is automatically filtered by CodeIgniter.  CodeIgniter User Manual excerpt proves this fact: “Beyond simplicity, a major benefit to using the Active Record features is that it allows you to create database independent applications, since the query syntax is generated by each database adapter. It also allows for safer queries, since the values are escaped automatically by the system.”

3,XSS Attacks: An XSS or Cross Site scripting attack is unarguably the common reason for the demise of web applications. A XSS attack works by a hacker crafting a malicious URL into the browser in order to compromise the security of the application. CodeIgniter has a built in XSS filter which is initialized automatically. In order to double check the security threats against XSS attacks, a Firefox add-on called XXS Me (download here) can be used to test the sample application against 96 different types of attacks. The results are shown in the image below. It shows that the all form input fields were not found unencoded, which means the XSS filter within CodeIgniter did its job.