Welcome Guest, Not a member yet? Register   Sign In
Question with isset on a search function?
#1

[eluser]Solarpitch[/eluser]
Hey Guys,

I have the following controller for doing a simple search on the site. Initially I take the search term as a post from the form and then the results are generated.

The user then has an option to select if they would like to view the results in a grid or list style, so the search term needs to be resubmitted to the function through the URI so the function can generate the results in the appropriate style.

Code:
function search()
{

$this->load->view('template/header');

// Get the search term from the submitted form        
$term = $this->input->post('term');


// This will get the style for the list, either "grid" or "list". This is for after
// the user has searched and then wishes to choose a style to display the results.

$list_style = $this->uri->segment(4);
                
$data['query'] = $this->product_model->search_keyword($term);
    

if($list_style == "grid"){
$this->load->view('pages/phones_grid', $data);
}
else
{
$this->load->view('pages/phones_list', $data);
}

//$this->load->view('template/footer');
}


Is there anyway I can say, if form is not being submitted then set term equal to uri->segment(4) instead of input->post('term')
#2

[eluser]thinkigniter[/eluser]
try
Code:
$term = $this->input->post('term');

$list_style = $this->uri->segment(4);

if( $term == FALSE ){
$term = $list_style;
}
I hope this is what you need.
#3

[eluser]Phil Sturgeon[/eluser]
Code:
function search($term = '', $list_style = 'grid')
{

$this->load->view('template/header');

// Get the search term from the submitted form if none provided in URL    
if($term == '') $term = $this->input->post('term');
                
$data['query'] = $this->product_model->search_keyword($term);

if($list_style == "grid"){
    $this->load->view('pages/phones_grid', $data);
}
else
{
    $this->load->view('pages/phones_list', $data);
}

//$this->load->view('template/footer');
}

That will allow search terms to be either uri segment 4 or post, and the list type is optional for uri segment 5, defaulting to 'grid'.




Theme © iAndrew 2016 - Forum software by © MyBB