Welcome Guest, Not a member yet? Register   Sign In
How Can I Use Language Class in Controller
#1

First of all, I made research but couldn't find anything about it.

I'm sending flash data to users when they update or add something. My controller file's related part is like this;

Code:
function hizmet_ekle()
        {
            if($this->mhizmetler->hizmet_ekle())
            {
                $this->session->set_flashdata('ok', 'hizmet sisteme eklendi!');
                redirect('panel/hizmetler');
            }
            else
            {
                $this->session->set_flashdata('hata', 'Bir hata oluştu. Lütfen tekrar deneyin!');
                redirect('panel/hizmetler');
            }
        }
And my view's related parts are like this;

Code:
<?php if($this->session->flashdata('ok')): ?>
                    <div class="alert alert-success fade in widget-inner">
                        <button type="button" class="close" data-dismiss="alert">×</button>
                        <i class="fa fa-check"></i> <?php echo $this->session->flashdata('ok');?>
                    </div>        
                <?php endif; if($this->session->flashdata('hata')): ?>
                    <div class="alert alert-danger fade in widget-inner">
                        <button type="button" class="close" data-dismiss="alert">×</button>
                        <i class="fa fa-times"></i> <?php echo $this->session->flashdata('hata');?>
                    </div>
                <?php endif; echo validation_errors('
                    <div class="alert alert-danger fade in widget-inner">
                        <button type="button" class="close" data-dismiss="alert">×</button>
                        <i class="fa fa-times"></i> ', '
                    </div>'); ?>

My system has a few different languages, it means I have to send different notification messages(session flashdata's) for each language but I can't use `lang` key in my controller file. How can I handle it?

Thanks in advance.
Reply
#2

Well... I think you should access flash data in the controller and not in the view.
Reply
#3

(This post was last modified: 11-07-2014, 04:08 AM by marcogmonteiro.)

And why can't you use the lang key in your controller?

Using the language helper you can just do something like:

PHP Code:
$this->session->set_flashdata('ok'lang('you_did_good')); 

in your language files you have the correct display for each language for the "you_did_good" key.
Website: marcomonteiro.net  | Blog: blog.marcomonteiro.net | Twitter: @marcogmonteiro | TILThings: tilthings.com
Reply




Theme © iAndrew 2016 - Forum software by © MyBB