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');
Use parser library for loading views.
$this->load->library('parser');
$data['content'] = $this->parser->parse('site/header', $data, TRUE);
$route['admin'] = 'admin/index';
// constant.php
define('SITE_NAME', 'zeeshanrasool');
$this->load->library('session');
// setting data in session
$this->session->set_flashdata('item', 'value');
// using data
$this->session->flashdata('item');
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.'/');
$this->db->trans_begin();
if ($this->db->trans_status()===FALSE)
{
$this->db->trans_rollback();
return True;
} else {
$this->db->trans_commit();
return False;
}
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;
switch($a){
case: 1
echo 1;
break;
case:5
echo 5;
break;
}
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
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)";
select * into outfile '/file.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
from zips;
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;
});
});
$(document).ready(function(){
var originalFontSize = $('html').css('font-size');
$(".resetFont").click(function(){
$('html').css('font-size', originalFontSize);
});
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"));
});
*/
var el = $('#id');
el.html(el.html().replace(/word/ig, ""));
from:http://www.99points.info/2010/03/mysql-php-codeigniter-css-jquery-and-ajax-working-tips/
0 comments:
Post a Comment