0

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

1
  • pls always response to the answers by giving some comments or ,if it helps you, by marking it as green and upvoting, it is the best way to thanks all the programmers Commented Jun 2, 2018 at 12:25

1 Answer 1

1

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);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

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.