Category Archives: Codeigniter
How to enable query string in codeigniter
How to enable query string in codeigniter
If you want to use query string like this :
index.php?page_no=10&id=12&ref=home_page
Go to application/config.php
change
$config[‘enable_query_strings’] = FALSE;
to
$config[‘enable_query_strings’] = TRUE;
Now you can use query strings in codeigniter controllers.
can use this How to enable query string in codeigniter.
How to get current date time in codeigniter?
How to get current date time in Codeigniter– It is pretty simple & quick to get the current time & date in Codeigniter. First, load date helper in the controller or autoload it in the _autoload file, After loading this helper you will be able to access its methods defined for time & date.
Get current date time with Date Format in Codeigniter.
Now let us go step by step to understand how to date helper is used.
Load Date Helper
First Make sure the date helper is loaded, If not then load it simply as below-
$this->load->helper('date');
Get Date Time
Once the date helper is loaded you get the current date and time as –
$format = "%Y-%m-%d %h:%i %A"; echo mdate($format); // this will print // 2017-09-06 08:15 PM
Date Format
You can pass the date time format to the date($format) function where the $format is the date format. Apart from Codeigniter DateTime, we can also use native date functions to get the current DateTime – For example, you can use the now() function to get the current time & date.
Codeigniter Date Time Demo
load->helper('date'); $format = "%Y-%m-%d %h:%i %A"; echo mdate($format); } } ?> |
If run the above example it will produce output something like this-
For More Details About Date Helper & Functions Read – Date helper
I hope this article was helpful for you.
How to display likes in facebook style in php
How to display likes in facebook style in php
Use the following function to format facebook likes, comments count
if(!function_exists(‘format_num’)){
function format_num($n) {
$arr = array(“K”, “M”, “G”, “T”);
$out = “”;
while ($n >= 1000 && count($arr ) > 0) {
$n = $n / 1000.0;
$out = array_shift($arr );
}
return round($n, max(0, 3 – strlen((int)$n))) .” $out”;
}
}
To use this function in codeigniter add this function in
system/helper/url_helper.php file
will give like counts in facebook style.
Ex 100 likes
1000 likes = 1 K
10000 likes = 10 K
To load library in codeigniter view
You can load library in codeigniter view or anywhere using this trick.
go to – system/helpers/url_helper.php
Add the following function :
function loadLibrary($libraryName)
{
$ci = & get_instance();
$ci->load->library->($libraryName);
return $ci->$libraryName;
}
Now in your view Or any where you want to load library just call this function :
example in sample_view.php we have to load library :
just call the function :
loadLibrary(‘library_name’);
how to load model in view codeigniter
How to load model in view codeigniter
You can load models in Codeigniter view as :
Example :
$this->load->model(‘product’);
$result =$this->product->productList();
foreach($result as $row) {
echo $row[‘product_name’];
}
Remove index.php in codeigniter
There are only two changes required to Remove index.php in codeigniter.
1. Config.php change.
2. Add code in .htaccess file placed at the root of your application.
Remove index.php in codeigniter
Add the above following code in .htaccess file to Remove index.php in codeigniter.
RewriteEngine on RewriteCond $1 !^(index\.php|resources|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA]
And
go to application/config.php
and change :
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
Or You Can Use Also :
DirectoryIndex index.php RewriteEngine on RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]
.htaccess is placed at the root of your application.
After Adding the above changes index.php will be removed in codeigniter.
Download Codeigniter
codeigniter’s latest stable version is V 2.2.0(Current Version). You can download it from
https://ellislab.com/codeigniter/user-guide/installation/downloads.html
You can also download it from github
What is Codeigniter?
CodeIgniter is an open source rapid development web application framework, for use in building dynamic web sites with PHP. The first version was released on February 28, 2006
The latest & stable version of codeigniter is 2.2.0
Codeigniter is very good for rapid application development with small footprints. Codeigniter has good documentation.