التخطي إلى المحتوى الرئيسي

المشاركات

عرض الرسائل ذات التصنيف Codeigniter

OOP'S in PHP

OOP'S in PHP, Class, and Object, Abstraction and Encapsulation, etc  OOP'S means object-oriented programming structure, It is used to create a real-world based application using desktop and web technology. OOP provides a set of rules to implement dynamic features in an application. for example, if we want to provide security , dynamic memory allocation, code reusability, data accessibility option in your application then you should implement OOP's programming. Rules of oop's                                                                             Features class and object                                                         provide all fea...

What is Codeigniter

What is Codeigniter:- it is an MVC framework that is used to distribute the code in a layered architecture . M means Model which is used to provide d atabase connectivity operation. V means View:-  it will contain the design layer of an application using HTML, CSS, JS, and Jquery. C means Controller:- it will contain the Program Code or Program Logic of an application. it is a start-up layer of an application. MVC is a design pattern to distribute the project on multiple project layers. The flow of MVC:-                             2  1                          View Controller ->                             3                             Model means the first controller will be load...

How to create form to take input from user's in CI

How to create a form to take input from user's in CI:- 1:-   Create Controller and define  index() 2     Create view file and design form for simple interest (3 text field,1 submit button with form tag) 3  write form action with the controller method name     <form action="<?php echo site_url(); ?>/Controllername/methodname" method="post">    </form> 4 load view under index() of controller 5 create an action method to write code on the controller 6 define  url helper to use base_url() in application/config/autoload.php 7 set route Program Code Controller <?php class SI extends CI_Controller {     function index()     {       $this->load->view('siview');     }     function silogic()     {     //$p= $_POST['txtp'];     //$r= $_POST['txtr'];     //$t =$_POST['txtt']; ...

How to create a page using View file and Controller class

How to create a website using View file and Controller class:-  1   Create a Controller and define five different Method <?php class Guest extends CI_Controller {     function index()     {        $this->load->view('header');        $this->load->view('home');        $this->load->view('footer');     }     function about()     {        $this->load->view('header');        $this->load->view('about');        $this->load->view('footer');     }     function service()     {        $this->load->view('header');        $this->load->view('service');        $this->load->view('footer');     }     function gallery()    ...

Form Validation in CI :-

Form Validation in CI:- It is used to validate the form using the Form Validation Library.CI Provide a set of classes and methods to implement validation. $this->form_validation->set_rules('elementname','message','validationtype'); for example <input type="text" name="txtuser"   /> $this->form_validation->set_rules('txtuser','username ','required'); if($this->form_validation->run()==False) {    $this->load->view('viewname'); } else {      action code } ...................................................................................................... STEP FOR VALIDATION:- 1) Create Controller 2) Create One Method for Load View and Action 3) Set Form Validation library in autoload.PHP 4) Create a View file 5) Manage Validation Code and Load View 6) Set Validation Error Message in View Page Code of the controller:- <?php class Reg extend...

User Define Helper and Library in Codeigniter

Helper:- It is used to contain predefine functionality under a Codeigniter application. Codeigniter provides cookie, URL, etc helper to provide features. Helper always will be declared as a procedural pattern. If we want to provide common features in an application then we can create a helper. Step to create helper:- 1 create helper file under application/helper directory 2 _helper must be declared under filename as a suffix   filename_helper.php 3 define function under the helper file as a procedural pattern.   function functionname()   {   } 4 load this helper file in autoload.php  or constructor  $this->load->helper('helperfile') 5 Call helper under the controller method. helper file code:- <?php function viewnotice() { echo "<marquee><h1 style='color:red;'>CI batch will be finished earlier hence prepare project</marquee></h1>"; } ?> Controller:- <?php  functi...

Hooks in Codeigniter

Hooks in Codeigniter:-   Hooks are used to providing an implicit event method that will be called during the application flow cycle. for example, if we want to call functionality under before System load, System unloads, Before Constructor, after constructor then we can use hooks. Codeigniter Provide Multiple hooks point to define the application functionality. CI provides multiple hooks point to write functionality. The following is a list of available hook points. pre_system:-  call before application load pre_controller:-  call before controller load post_controller_constructor: -  call with constructor initialization post_controller  Called immediately after your controller is fully executed. display_override  Overrides the  _display()  method, cache_override  Enables you to call your own method instead of the  _display_cache()  method in the  Output Library . post_system  Called after the final ren...

Database Connectivity in Codeigniter with MYSQL Database

Database connectivity from MySQL to CI? ......................................................................................... steps1st:- create database and table from MySQL database using PHPMyAdmin step2nd:- open project folder and edit config/database.php and edit username, password, database username=root password=' ' database= dbname step3rd:- create controller and load view and create an action method in the controller step4th create view form according to the table in the view file step5th create a model class and define a method for data insertion under the model folder class Modelname extends CI_Model {       function methodname()       {       }    } step6:- load database.php file under model class constructor function __construct() {    parent::__construct();    $this->load->database(); } step7:- create a method on the model and write data i...

Session and Cookies in Codeigniter?

A session is a persistent object that is used to retain data of an application after server response under browser cookie. Session data can be accessed into multiple web pages directly hence it is also called a global variable of PHP. In Codeigniter session has been defined under the predefine library hence first we load the session from the session library under autoload.php or constructor of controller. before use session encryption key should be set on the config.php file for security concerns. Syntax of session to set data in the session $this->session->set_userdata('key','value'); to get data from the session $this->session->userdata("key"); to destroy session data if we destroy particular data then we can use this -> session -> unset_userdata ( 'some_name' ); $this->sessio->sess_destory(); We should always set sessions under the login page and they should be verified under the dashboard page. A session is used to provide i...

Cookie Concept in CI

What is Cookie? A cookie is used to store information under a web browser, every browser contains a separate directory to store data under the cookie. The cookie will be private. The session will be stored data under the cookie folder by default. Step for Cookie:- 1 Load cookie helper in autoload.php 2  first set cookie    $this->input->set_cookie('key','value',time);     $this->input->set_cookie('cuid',$user,3600);     $this->input->set_cookie('cpwd',$pass,3600); 3   get cookie data     $data= array('a'=>$this->input->cookie('cuid'),'b'=>$this->input->cookie('cpwd'));             echo $this->input->cookie('key') 4 delete cookie data      delete_cookie('key');

File Uploading Concept in CI

File Uploading Concept in CI:- It is used to upload external content in an application. The file is a collection of records that is used to store data under computer harddisk. CI provides Upload Library to upload data. Step1st:- Create a Controller to upload a file and create a view and load view under the controller method. Step2nd:- Create Folder under project under application Step3rd:- Create action method do_upload() and write file uploading script Step4th:- Run application to change config.php Code of Controller <?php class FileUpload extends CI_Controller {     function index()     {        $this->load->view('fileview');     }   function do_upload()    {       $config['upload_path'] = './upload/';       $config['allowed_types']        = 'gif|jpg|png';        $this->load->library('u...

Ajax Tutorials in Codeigniter

Ajax Implementation in Codeigniter Ajax means Asynchronous Javascript and XML, it is used to partially update the content of a web page excluding complete web form. Ajax improves the performance of web application and provide dynamic programming approach without reloading and submit the data. for example, if we create a registration form and we want to check that email already exists when user switches to next text field then we can create ajax code to check the email id. when we select country then the state list and when we select the state then the city list will be populated by AJAX. when we search from Facebook or Google search box then data will be populated when we press any key that will be managed by Ajax. Role of JavaScript or Jquery:- It is used to handle the event in Ajax Process, which means if we select a dropdown list and display data into another dropdown list will be managed by AJAX. Role of XML:- XML means Extensible markup language which is us...

Ajax Example With Country ,State and City in Codeigniter

1)First Create database and Table Complete Code of Controller:- <?php class AjaxExample2 extends CI_Controller {    function __construct()    {     parent::__construct();     $this->load->model('stumodel');    }    function index()    {       $data['r'] = $this->stumodel->getCountry();     $this->load->view('countryview',$data);    }    function searchdata($id)    {                   $data['res']=$this->stumodel->statesearch($id);             $this->load->view('stview',$data);    } } ?> Complete Code of Model <?php class Stumodel extends CI_Model {     function __construct()     {     parent::__construct();     $this->load->database()...

Cart Library in Codeigniter

Using this we can create Shopping cart features in an application. CI Provide cart library to implement this functionality. Step to Implement Card Functionality:- 1)  Create Controller 2 ) Load cart library under Controller Constructor $this->load->library('cart') 3) Create Controller  Index method and Add Multiple Items into cart 4) Create View  and show cart content Complete Code of Cart:- <?php class Shoppingcart extends CI_Controller {  function __construct()  {   parent::__construct();   $this->load->library('cart');     }      function index()      {       $this->cart->destroy();        $data = array(         array(                 'id'      => 'sku_123ABC',         ...