Home » , , , » Tutorial Codeigniter, PHP, CSS, MySQL, and JQuery

Tutorial Codeigniter, PHP, CSS, MySQL, and JQuery




Codeigniter

Codeigniter is PHP framework which is light weight and very easy to configure and a lot of help available online.
Use separate models for each module so that tracking can be easy.
$this->load->model('Login');
Front and admin should be handled with separate controllers.
Use parser library for loading views.
$this->load->library('parser'); 
$data['content'] = $this->parser->parse('site/header', $data, TRUE);
In config folder routes file will help you to create pretty urls.
$route['admin'] = 'admin/index';
Define all your global constants in config/constant.php or create a separate file for this.
// constant.php
define('SITE_NAME', 'zeeshanrasool');
Use flash session for your messages to users.
$this->load->library('session');
// setting data in session
$this->session->set_flashdata('item', 'value');
// using data
$this->session->flashdata('item');
Don’t call any model function inside views as it is not a valid in MVC.
If you want to keep your application folder outside system folder then you need to change path in index.php on main root.
// it is default path
define('BASEPATH', $system_folder.'/');
// change it to
define('BASEPATH_NEW', '../your_folder/');
// above path will be use like this
define('APPPATH', BASEPATH.$application_folder.'/');
Use rollback functions to keep track the functions otherwise revert all of your actions on failed.
$this->db->trans_begin();
if ($this->db->trans_status()===FALSE)
{
$this->db->trans_rollback();
return True;
} else {
$this->db->trans_commit();
return False;
}
Include all of you css and js files in views separately from controller.
Don’t include all CSS or JS files on single page i-e index.php 

PHP

Use switch conditions instead of  if / else in case of using too much conditions. Switch condition is much faster than if / else.
if($a==7)
echo 1;
else if($a==5)
echo 5;
For multiple conditions its best to use switch condition.
switch($a){
case: 1
echo 1;
break;
case:5
echo 5;
break;
}
Keep all particular functionality like, code for uploading a file, getting date in specific format etc in separate functions so that you can re-use them instead f writing it again.
Use server side validation for required input fields with client side validation.
Single quotes is faster than double quotes for string or query in quotes.
$query = "Select * from table"; 
$query = 'Select * from table'; // single quoted
Keep error reporting on, so that notices and warnings may be fixed. These small notices may produce some problems on your server online.
Comment your code, what you have done. So next time you are any other developer understand your code easily.
Use .htaccess to put some securities on your code.
Declare all variables properly so that they produce no problem in executions. 

MYSQL

Get last 24 hours or 1 day records in mysql.
"select count(*) as cnt from log where date >= 
DATE_SUB(CURDATE(),INTERVAL 1 DAY)"
;
Export your table to CSV file.
select * into outfile '/file.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
from zips;
Don’t use DISTINCT when you have or could use GROUP BY,
LIMIT m,n may not be as fast as it sounds.
Don’t use ORDER BY RAND() if you have > ~2K records
Avoid using IN(…) when selecting on indexed fields, It will kill the performance of SELECT query.
Minimize traffic by fetching only what you need.
1. Paging/chunked data retrieval to limit
2. Don’t use SELECT *
3. Be wary of lots of small quick queries if a longer query can be more efficient.
Do not duplicate indexes.
Avoid wildcards at the start of LIKE queries. 

CSS

Keep css Simple.
Don’t use hacks unless its a known and documented bug.
Take care of margins and padding on all elements.
Avoid using too much absolute positioning.
Validate your code 

JQuery

Disable right click.
$(document).ready(function(){
$(document).bind("contextmenu",function(e){
return false;
});
});
Re-size font.
$(document).ready(function(){
var originalFontSize = $('html').css('font-size');
$(".resetFont").click(function(){
$('html').css('font-size', originalFontSize);
});
Equal height columns.
function equalHeight(group) {
tallest = 0;
group.each(function() {
thisHeight = $(this).height();
if(thisHeight > tallest) {
tallest = thisHeight;
}
});
group.height(tallest);
}
/*
Usage:
$(document).ready(function() {
equalHeight($(".recent-article"));
equalHeight($(".footer-col"));
});
*/
Remove a word in a text
var el = $('#id');
el.html(el.html().replace(/word/ig, ""));
Preloading images
jQuery.preloadImages = function()
{
for(var i = 0; i").attr("src", arguments[i]);
}
};
 
// Usage
$.preloadImages("
image1.gif", "/image2.png", "image3.jpg");
 

from:http://www.99points.info/2010/03/mysql-php-codeigniter-css-jquery-and-ajax-working-tips/
Share this article :

0 comments:

Post a Comment

 
Support : Femin Collection | Habitat Design | Kreatifa Media
Copyright © 2013. Kreatifa Media - All Rights Reserved
Template Created by Habitat Design Published by Kreatifa Media
Proudly powered by Blogger