Showing posts with label cgi. Show all posts
Showing posts with label cgi. Show all posts

18 Oct 2016

Installing Codeignitor on Xampp

Folder structure of Codeigntior


Step1):config base_url and index_page.
Path: application/config/config.php

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

Open addresses in browser - http://localhost/cgi[project name = cgi] or localhost or localhost/xampp/

Welcome

Optional

Database: application/config/database.php

In Codeigniter Routing is very important. Default route for web application.
$route[‘default_controller’] = “Welcome”;
$route[‘404_override’] = ”;

Here I changed welcome to login
$route[‘default_controller’] = “login”;
$route[‘404_override’] = ”;

For handling the form data you have to ser TRUE instead of FALSE in config.php
Global XSS Filtering.
$config[‘global_xss_filtering’] = TRUE;

Creating Project From Scratch in CodeIgniter 3.1.0 on Xampp


Step 1) 
Download:

  • Codeigniter 
  • Twitter Bootstrap (http://getbootstrap.com/2.3.2/)

Create New Folder (project name) in Xampp htdocs and Combine sub-folders of both
Bring .htaccess file from application folder to root folder
Some of files like (User Guide or licence are not needed to copy here)

Step 2)
.Htaccess file (Below permission) shows Permission denied error at Front-End. It need to replace with another code

Code to Remove
<IfModule authz_core_module>
    Require all denied
</IfModule>
<IfModule !authz_core_module>
    Deny from all
</IfModule>

This will remove index.php from Url
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

Codeigniter 3.1.0 Overview

Config folder files -

  • autoload- We need to include library in autoload before used so it will load automatically when needed.
  • database- to include DB
  • route- to handle default controllers like 404 welcome etc

Index.php - Any Url Request will be handle by this file like (about us or contact us)

  • index.php/[controller]/[method]
  • Controllers and functions/methods are defined in this file
  • Initially We Need to Define Controller like Welcome.php
  • multple functions/method in controller
  • class Welcome extends CI_Controller {
  • File must be protected following this condition
    • defined('BASEPATH') OR exit('No direct script access allowed');
  • If we call to (index.php/Welcome.php/)
    • It shows error because we didn't define index () function
    • public function index()
    • {
    • $this->load->view('welcome_message');
    • }
  • But if we call to another function Public function test ()
    • (index.php/Welcome.php/test)
    • It will works even without index () function

Codeigniter 3.1.0 Lecture 1 (Controllers and View)

Add test function and open the Url http://localhost/cig/index.php/welcome/test


Url Structure (http://localhost/cig/index.php/Controller/function)

Lets create New Controller UnderConstruction and view under_construction
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class UnderConstruction extends CI_Controller {

/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/underconstruction
* - or -
* http://example.com/index.php/underconstruction/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/underconstruction/<method_name>
* @see https://codeigniter.com/user_guide/general/urls.html
*/

public function index()
{
$this->load->view('under_construction');
}
public function test() {
echo "Works Well";
}
}
It will show 404 error - if index () function is missing
http://localhost/cig/index.php/underconstruction/test - Open this Url
It will provoke the specific function inside the controller

In View Section just copy paste welcome_message and little edit it.
$this->load->view('blob/under_construction');
If our view under_construction is located in view->blog-> then we must have to mention blog, as by default all views are fetched from root folder.