0

How do I pass to codeigniters controller a parameter via URL? I use IgnitedTables to display jquery DataTable. Actually I use ajax to populate table (cms_datatable()) I would like to pass somehow a language parameter via url to can filter content on language

I have the following

public function cms($cms_lang = '') {

    $this->cms_lang = $this->session->userdata('cms_lang');
    if(isset($cms_lang)){
        $this->cms_lang['current_lang'] = $cms_lang;
    } else {
        $this->cms_lang['current_lang'] = 'de';
    }

        $tmpl = array('table_open' => '<table id="cms_table" border="0" cellpadding="2" cellspacing="2" class="table table-striped table-primary table-condensed">');
        $this->table->set_template($tmpl);
        $this->table->set_heading('<input name="id[]" type="checkbox">', 'Title', 'SEF URL', 'Letztens bearbeitet', 'Status');
        $this->load->view('admin/admin', $this->data);
    }

    public function cms_datatable() {
    error_reporting(-1);
    // var_dump($this->cms_lang['current_lang']); returns NULL
    $this->datatables->select('id,title,sef_title, creation_date,status')            
            ->edit_column('title', '<a href="/admin/dashboard/edit_post/$1">$2</a>', 'id, title')
            ->unset_column('creation_date')
            ->add_column('creation_date', '<span class="label label-danger">$1</span>', 'creation_date')
            ->unset_column('status')
            ->add_column('status', get_buttons('$1'), 'id')
            ->from('ci_content')
            ->where('language', $this->cms_lang);
    echo $this->datatables->generate();
}

than I try to override the default value of variable $lang like

domain/admin/cms/en

but my var_dump($lang) shows the defualt value

routed as

$route['admin/cms']  = "admin/dashboard/cms";
$route['admin/cms/(:any)']  = "admin/dashboard/cms/$1";
4
  • CodeIgniter URLs are as such: http://yoursite.com/controller/method/paramN. So you need to set your route to admin/dashboard/cms/cms_datatable/$1. Commented Jan 3, 2014 at 16:35
  • sorry I have to make some corrections Commented Jan 3, 2014 at 16:42
  • 1
    Have you considered _remap() yet? Commented Jan 4, 2014 at 11:38
  • I got it working with a session id but is not the desired result thanks for the tip _remap it can be usefull for my frontend architecture Commented Jan 4, 2014 at 12:21

1 Answer 1

2

your controller fn name is cms_datatable but you're not calling it.

Try using the url routes:

$route['admin/cms']         = "admin/dashboard/cms_datatable";
$route['admin/cms/(:any)']  = "admin/dashboard/cms_datatable/$1";

That route assumes that:

  • admin is your folder
  • dashboard is your controller
  • cms_datatable is your controller fn

Also, re-reading your question, I am not sure why you want to pass language variables to EACH controller? Just set it in session and check it that way. Override the default if the session has a different language defined. Having every controller check this is not good form.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you for your feedback I started to refactor the codes and I try to use a session variable to pass the language variable but on call doesn't seems to have value
if this answer solved / answered your current question don't forget to up vote / mark as solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.