I have an application build in Codeigniter framework.which have functionality of multi language.It works fine In view to convert the each line.But for alert messages which is set from controller i try to use the language key but failed to show the message on view in multi language.
Here is the code of controller from the message has been set to show on view:-
the function of controller to set the message:
function serial_coupon()
{
$admin_session_data= $this->session->userdata('user_logged_in');
$key=$this->input->post('serial');
$res=explode("000",$key);
$key=$res[1];
$result['coupon']=$this->provider_model->get_coupon($key);
if(empty($result['coupon']))
{
$msg=$this->lang->line('language_srch_msg');
$this -> session -> set_flashdata('message',$msg);//if no search found than set the message.
redirect('/provider/');//provider is controller
}
else
{
$this->load->view('header',$admin_session_data);
$this->load->view('show_coupon',$result);
$this->load->view('footer',$admin_session_data);
}
}
Hence it comes to the Provider controller's Index Function to send the message on view:-
function index()
{
$msg=$this->session->flashdata('message');//get the message
$result['msg']=$msg;and set to the array to send in view
$result['rows']=$this->session->userdata('provider_detail');
$user_id=$result['rows'][0]['id'];
$result['coupons']=$this->provider_model->show_coupons($user_id);
$this->load->view('header');
$this->load->view('provider_interface',$result);
$this->load->view('footer');
}
So the message should be display in view:
<p><?php echo $msg; ?></p>
And the other lines where i am using language key Like: for name:
<?php echo $this->lang->line('language_name');?>
Now please Let me know how can i use the above language key for message in controller??
Thanks In advance and still any doubt feel free to Ask.
Short description : the problem is not to show the falshdata message.i want the message should be in a particular language in which the user selected.my application in multi language in which the user can select the language from drop down box.and the whole content in convert in to the selected language .but the alert messages comes from controller so how can i convert them in selected language?
I changed my code in function search_coupon but it works for only English language not for Portuguese.Here is my constructor code of provider controller:
public function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->helper('form');
$this->load->library('session');
$this->load->model('provider_model');
$lng=$this->session->userdata('about_language');
if($lng=='' )
{
$this->load->language('language','english');
}
else
{
$this->load->language('language',$lng);
}
if($this->session->userdata('provider')=="")
{
redirect('/login/', 'refresh');
}
}
Code for select The language using ajax:
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#port').click(function(){
var dummy = 2;
$.ajax({
type: "POST",
url: "<?php echo BASE_PATH; ?>/session/sessions",
data: "&ID="+dummy+ "&lang="+'portuguese',
success: function(response)
{
if (response == false)
{
location.reload();
}
}
});
});
jQuery('#eng').click(function(){
var dummy = 1;
$.ajax({
type: "POST",
url: "<?php echo BASE_PATH; ?>/session/sessions",
data: "&ID="+dummy+ "&lang="+'english',
success: function(response)
{
if (response == false)
{
location.reload();
}
}
});
});
});
</script>
And here is the session controller :
function sessions(){
$value= $this->input->post('ID');
$lang= $this->input->post('lang');
$lang=$this->session->set_userdata('about_language',$lang);
return $lang;
}