A Codeigniter Helper to convert your price from database from a currency to another
Is very frequently that inside your sites you need to convert your price from a currency to another. You need to have valid database connection and tables to use this helper.
If helper is loaded in autoload you can use it in evere view file like:
<?php echo currency($row->price);?> <?php echo label();?>
where we pass data from database in helper function like in this example object $row->price and thath call helper function to display currency label from session. Use sql file to see table structure.
First set link in your site with
<a href="<?php echo base_url() ?>home/set_currency/usd or eur or bgn">
Then simply set the name of the currency in session data like
$this->session->set_userdata('set_currency', $currency);
You need function in some controller to set data - Example:
public function set_currency($currency = "")
{
$currency = ($currency != "") ? $currency : "usd";
$this->session->set_userdata('set_currency', $currency);
redirect(base_url());
}
In the end just call helper in view like:
<?php echo currency($row->price);?> <?php echo label();?>
CodeIgniter 2.x, 3.x PHP 5.2 or gretaer
Drag and drop the currency_helper.php in into your application directories. Load it from your application/config/autoload.php using:
$autoload['helper'] = array('currency');