Gulzar Ali
Gulzar Ali

Reputation: 75

Pass query string to same method in controller in codeigniter

I am Trying To Reload Contents Of Page. Through link button Filter In PHP By Passing Some Value Through Query String To Controller Method. The Controller Method Loads The Same Page From Where I am Passing Query String. But The View Is Not Reloading. But If I Call The Controller Method Some Other View It Works Fine. here is my code

mainview.php

<a href="<?=base_url()?>maincontroller?language=English">English</a>

maincontroller.php

Here Is The Index Method Of Controller.

    $movielanguage=$this->input->get('language');
    if(!empty($movielanguage))
        {
            $moviedata['popularmovies']=$this->main_model- 
            >getmoviebylanguage($movielanguage);
        }

    $moviedata['allmovies']=$this->main_model->getAllMovies();
    $this->load->view('home/mainview.php',$moviedata);
}

Here View Does Not Refresh Its Contents How Can I Solve This

Upvotes: 0

Views: 239

Answers (1)

Pradeep
Pradeep

Reputation: 9717

Hope this will help you :

First if you want a single view ,should put you code it in if else condition and second assign your data in same variable

Your code should be like this :

public function index()
{
    $movielanguage=$this->input->get('language');
    if(! empty($movielanguage))
    {
        $moviedata['movies']=$this->main_model->getmoviebylanguage($movielanguage);
    }
    else
    {
        $moviedata['movies']=$this->main_model->getAllMovies();
    }

    $this->load->view('home/mainview.php',$moviedata);
}

Second : and if you want to add different view for different category of movies

You can do like this :

public function index()
{
    $movielanguage=$this->input->get('language');
    if(! empty($movielanguage))
    {
        $moviedata['popularmovies']=$this->main_model->getmoviebylanguage($movielanguage);
        /*popularview is just an example*/
        $this->load->view('home/popularview.php',$moviedata);

    }
    else
    {
        $moviedata['allmovies']=$this->main_model->getAllMovies();
        /*allview is just an example*/
        $this->load->view('home/allview.php',$moviedata);
    }
}

Upvotes: 1

Related Questions