Skip to content

Commit

Permalink
Add language switcher method to Home controller
Browse files Browse the repository at this point in the history
  • Loading branch information
daif committed Apr 16, 2017
1 parent 22509dc commit 9eb14b4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
19 changes: 18 additions & 1 deletion application/controllers/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,24 @@ public function index()

}


/**
*
* Switch user language.
*
*/
public function getLang($lang)
{
$this->load->library('user_agent');
if($lang == 'arabic' || $lang == 'english') {
$this->session->set_userdata('lang', $lang);
set_message('language_switched','success');
}
if(base_url() == substr($this->agent->referrer(), 0, strlen(base_url()))) {
redirect($this->agent->referrer());
} else {
redirect('/');
}
}
}

/* End of file Home.php */
Expand Down
19 changes: 0 additions & 19 deletions application/controllers/User/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,6 @@ public function index()
$this->data['row'] = $this->user->find($this->userdata->user_id);
}

/**
*
* Lang Page for this controller.
*
*/
public function getLang($lang)
{
$this->load->library('user_agent');
if($lang == 'arabic' || $lang == 'english') {
$this->session->set_userdata('lang', $lang);
set_message('language_switched','success');
}
if(base_url() == substr($this->agent->referrer(), 0, strlen(base_url()))) {
redirect($this->agent->referrer());
} else {
redirect('/User/Dashboard');
}
}

/**
*
* getUpdate for this controller.
Expand Down
4 changes: 2 additions & 2 deletions application/views/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@
<ul class="dropdown-menu extended pro-menu fadeInUp animated" tabindex="5003" style="overflow: hidden; outline: none;">
<li><a href="<?php echo base_url() ?>User/Account"><i class="fa fa-briefcase"></i> <?php echo lang('profile')?></a></li>
<?php if($this->session->userdata('lang') == 'arabic'){ ?>
<li><a href="<?php echo base_url() ?>User/Account/lang/english"><i class="fa fa-language fa-fw"></i> English</a></li>
<li><a href="<?php echo base_url() ?>Home/lang/english"><i class="fa fa-language fa-fw"></i> English</a></li>
<?php } else { ?>
<li><a href="<?php echo base_url() ?>User/Account/lang/arabic"><i class="fa fa-language fa-fw"></i> عربي</a></li>
<li><a href="<?php echo base_url() ?>Home/lang/arabic"><i class="fa fa-language fa-fw"></i> عربي</a></li>
<?php } ?>
<li><a href="<?php echo base_url(); ?>Auth/Login/logout"><i class="fa fa-sign-out"></i> <?php echo lang('logout')?></a></li>
</ul>
Expand Down

0 comments on commit 9eb14b4

Please sign in to comment.