Welcome Guest, Not a member yet? Register   Sign In
filter and redirect to same page
#1

[eluser]Mutsop[/eluser]
Hi before I continue here is my code Smile
Code:
function index($offset = 0){
        if (!$this->ion_auth->logged_in())
        {
            //redirect them to the login page
            redirect('administrator/login', 'refresh');
        }
        else
        {
            // offset
            $uri_segment = 3;
            $offset = $this->uri->segment($uri_segment);
            
            // load data
            $rubriek = $this->input->post('rubriek');
            $data['action'] = site_url('admin/nieuws/'.$rubriek);
            $nieuwsAll = $this->nieuws_model->get_paged_list($this->limit, $offset, $rubriek)->result();

            // generate pagination
            $this->load->library('pagination');
            $config['base_url'] = site_url('admin/nieuws/'.$rubriek);
            $config['total_rows'] = $this->nieuws_model->count_all();
            $config['per_page'] = $this->limit;
            $config['uri_segment'] = $uri_segment;
            $this->pagination->initialize($config);
            $data['pagination'] = $this->pagination->create_links();
            
            // generate table data
            $this->load->library('table');
            $tmpl = array ( 'table_open'  => '<table border="0" cellpadding="10" cellspacing="0" class="table_main">' );
            $this->table->set_template($tmpl);
            $this->table->set_empty("&nbsp;");
            $this->table->set_heading('Datum', 'Rubriek', 'Titel', 'Acties');

            foreach ($nieuwsAll as $nieuws){
                $this->table->add_row(date('d-m-Y',strtotime($nieuws->datum)), $nieuws->rubriek, $nieuws->titel,
                    anchor('admin/nieuws/view/'.$nieuws->id,'view',array('class'=>'view')).' '.
                    anchor('admin/nieuws/update/'.$nieuws->id,'update',array('class'=>'update')).' '.
                    anchor('admin/nieuws/delete/'.$nieuws->id,'delete',array('class'=>'delete','onclick'=>"return confirm('Bent u er zeker van dit nieuws te verwijderen?')"))
                );
            }
            $data['table'] = $this->table->generate();

            // load view
            $this->load->view('admin/header');
            $this->load->view('admin/nieuwsLijst', $data);
            $this->load->view('admin/footer');
        }
    }

Now, As I mentioned in a previous post, I have a combobox which should filter my table (not set in a different order, but simple filter out).
Now here is my model:
Code:
function get_paged_list($limit = 10, $offset = 0, $rubriek){
        if(!$rubriek == ""){
            $this->db->where('rubriek', $rubriek);
        }
        $this->db->order_by('datum','asc');
        return $this->db->get($this->tbl_nieuws, $limit, $offset);
    }

No when i submit my filter, i get following url for example:
"/admin/nieuws?rubriek=ateam"

I dont mind it being ?rubriek=something.... But it does give me an "404 Page Not Found".

Any ideas why?
I'm using the same index function for two reasons, else I have to remake a whole new table and wont be able to refactor much, and second, it is to learn Smile

Regards
#2

[eluser]Nick_MyShuitings[/eluser]
Usually when you want to pass parameters to a controler/method pair you need to specify the method.

For example, if I just want to go to admin/nieuws/index (folder/controller/method) then I can actually just go to admin/nieuws. But if I want to pass parameters to that index function then I would need to specify it: ie (admin/nieuws/index/parameter1/parameter2)

I'm not a big fan of using the query string format, but the same should apply.
#3

[eluser]Mutsop[/eluser]
k, so by adding the index and setting the filter form to method="POST" it does filter everything which is GREAT Big Grin

BUT yet offcourse, as most solution comes with another problem, same here....

First, my URI is one step behind.
step1: choose ateam -> URI is index
step2: choose bteam -> URI is ateam
step3: choose ateam -> URI is bteam

Second, my pagination stays at my maximum.
for example when I have my fyull list I have 2 pages... after filtering to just 3 results I still have 2 pages.

Third, My update ID ain't correct after filtering. Same principle as second problem.
#4

[eluser]Nick_MyShuitings[/eluser]
Code:
function index($offset = 0){
        if (!$this->ion_auth->logged_in())
        {
            //redirect them to the login page
            redirect('administrator/login', 'refresh');
        }
        else
        {
            // offset
            $uri_segment = 3;
            $offset = $this->uri->segment($uri_segment);


Here is what I've never liked about the standard example of the pagination class. You see at the beginning of the function you are defining $offset. Then later you are overwriting offset with the uri segment 3.

Here's the catch... when you are posting to "admin/nieuws/'.$rubriek" when that gets to the controller its going to assign rubriek to $offset. The easier way then using the uri is simply to maintain a consistent order so something like this
Code:
function index($rubriek = '', $offset= 0) {

Then after some testing you could eliminate this line
Code:
$offset = $this->uri->segment($uri_segment);

Remember the two ways to pass info to your method:
1) controller/method/parameter1/parameter2
2) post or get

Here you are mixing those to ways, and thus having some arguments with the offset for the pagination.




Theme © iAndrew 2016 - Forum software by © MyBB