php - Pass query string to same method in controller in codeigniter

967

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

69

Answer

Solution:

Hope this will help you :

First if you want a single view ,should put you code it inif 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);
    }
}

People are also looking for solutions to the problem: php - Mysql add column from another table (no reference id)

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.