CODEIGNITER BASIC DOCUMENTATION

Framework         : CodeIgniter MVC

Database             : MySql

HTML, JS, CSS

 

FRONT END

HOME

URL: http://localhost/yourproject/

 

File Path:

/application/model/site/

/application/view/site/

/application/controller/site/

 

BACK END

 

Admin Home

URL: http://localhost/yourproject/admin/dashboard

 

File Path:

/application/model/admin/

/application/view/admin/

/application/controller/admin/

 

SETUP GUIDE

 

Configuration Files:

General path     : /application/config/

config.php          : All configuration set-up

database.php    : Only db configuration

routes.php         : Website route, here we can declare what is default page.

autoload.php    : We can load automatically specific helper class, library class,

modal, languages and more

 

example: $autoload[‘helper’] = array(“form”,”url”,”html”);

CSS / JS / Images:

 

Path:     /assets/admin/js

/assets/admin/css

/assets/admin/images

/assets/site/js

/assets/site/css

/assets/site/images

How to link CSS files in our Module

<?=link_tag(‘assets/admin/css/style.css’);?>

 

How to link JS files in our Module

<?=script_tag(‘scripts/tiny_mce.js’); ?>

Image Tag

<?=img()?>

 

 

Description

 

We have split the template as three major parts that is,

 

1. Header

2. Module Content

3. Footer.
In our each controller page code would be as follows,

 

public function index() {

$data = $this->db->get();

$data[‘page_title’] = ‘Trade Tantra Administrator dashboard’;

$this->load->view(‘admin/header’);       //common for all modules

$this->load->view(‘admin/dashboard’, $data);

$this->load->view(‘admin/footer’);        // common for all modules

 

}

 

Header contains meta data value and CSS and JS include.

Footer contains footer links and if necessary JS inclusion.

 

 

Reference:

http://www.web-and-development.com/codeigniter-remove-index-php-minimize-url/

http://jamshidhashimi.com/2013/04/12/dynamically-add-javascript-and-css-files-in-codeigniter-header-page/

https://github.com/EllisLab/CodeIgniter/wiki/Asset-Manager

http://dreamerslab.com/blog/en/codeigniter-view-library/

http://ellislab.com/codeigniter%20/user-guide/helpers/html_helper.html

DATABASE

Description: Where to code: (Model) Admin Path:

                   C:\xampp\htdocs\yourproject\application\models\admin\your_controller_name_model.php

Site Path:

                     C:\xampp\htdocs\yourproject\application\models\site\your_controller_name_model.php

 

How to call:

 

In Controller:

class Dashboard extends CI_Controller{

function blog() {
$this->load->model(‘admin/dashboard_model‘);
$data[‘records‘] = $this->dashboard_model->getRecord();
$this->load->view(‘dashboard’, $data);

}
}

 

In View:

<?php foreach($records as $row);?>

<?php echo $row->content; ?>

<?php } ?>

 

 

CODE STANDARD

SELECT QUERY:

 

$this->db->query(‘YOUR QUERY HERE’);

 

Example:

$sql=”SELECT foo FROM bar WHERE bof='”.$this->db->escape($bof).”‘ AND zot='”.$this->db->escape($zot).”‘”;

$this->db->query($sql);

 

If we have one table to get the result then use,

$this->db->get(‘tta_users’);

INSERT QUERY:

i)             $data = array(

‘title’ => ‘My title’ ,

‘name’ => ‘My Name’ ,

‘date’ => ‘My date’

);

 

$this->db->insert(‘mytable’, $data);

// Produces: INSERT INTO mytable (title, name, date) VALUES (‘My title’, ‘My name’, ‘My date’)

ii)

$data = array(

array(

‘title’ => ‘My title’ ,

‘name’ => ‘My Name’ ,

‘date’ => ‘My date’

),

array(

‘title’ => ‘Another title’ ,

‘name’ => ‘Another Name’ ,

‘date’ => ‘Another date’

)

);

 

$this->db->insert_batch(‘mytable’, $data);

 

// Produces: INSERT INTO mytable (title, name, date) VALUES (‘My title’, ‘My name’, ‘My date’), (‘Another title’, ‘Another name’, ‘Another date’)

 

UPDATE QUERY:

$data = array(

‘title’ => $title,

‘name’ => $name,

‘date’ => $date

);

 

$this->db->where(‘id’, $id);

$this->db->update(‘mytable’, $data);

 

// Produces:

// UPDATE mytable

// SET title = ‘{$title}’, name = ‘{$name}’, date = ‘{$date}’

// WHERE id = $id

DELETE QUERY:

 

$this->db->delete(‘mytable’, array(‘id’ => $id));

 

// Produces:

// DELETE FROM mytable

// WHERE id = $id

 

 

FINAL:-

QUERY CACHING:

If required we do the query caching.

 

$this->db->start_cache();

$this->db->select(‘field1’);

$this->db->stop_cache();

 

$this->db->get(‘tablename’);

 

//Generates: SELECT `field1` FROM (`tablename`)

 

$this->db->select(‘field2’);

$this->db->get(‘tablename’);

 

//Generates: SELECT `field1`, `field2` FROM (`tablename`)

 

$this->db->flush_cache();

 

$this->db->select(‘field2’);

$this->db->get(‘tablename’);

 

//Generates: SELECT `field2` FROM (`tablename`)

 

SECURITY (Escaping Queries ):

$this->db->escape()

 

Format your SQL Queries using following URL:

http://sqlformat.appspot.com/

 

 

Reference:

http://ellislab.com/codeigniter/user-guide/database/active_record.html

http://ellislab.com/codeigniter/user-guide/database/queries.html

http://ellislab.com/codeigniter/user-guide/database/results.html

http://ellislab.com/codeigniter/user-guide/general/models.html

1 Comment

  1. good information

    Verу sߋon this site will be famous amid all blogging useгs, dսe
    to it’ѕ gooԀ articles or reviews

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *