Welcome Guest, Not a member yet? Register   Sign In
Is there a way detect the use of pagination?
#1

[eluser]Kraig[/eluser]
Basically I have a home page that loads a template with $data when index() runs. Then there's a function in that same home controller that uses the pagination feature. However when I set
Code:
$config['base_url'] = base_url().'home/someFunction';
and then I click on one of the links it brings me to home/someFunction, which does load a view, but it won't retain the current template that loaded in index() function. I can't put it all in the index function because I am also using AJAX which calls the same function that the pagination is in.

So I'm thinking that I might be able to throw in an if statement...saying
if pagination detected (one of the links was clicked)
load template which will include the new variables
else
load the single view
#2

[eluser]DarkManX[/eluser]
The pagination sends an additional segment, just check for that segment in the if statement.
#3

[eluser]Kraig[/eluser]
Could you show me a quick example?
#4

[eluser]DarkManX[/eluser]
If your pagination url would be like that /product/list/<page>
Code:
if(isset($this->uri->segment(3))){
// pagination stuff
}else{
// no pagination stuff
}

But i dont know why you would want to check for pagination linked pages... You should redesign you application.
#5

[eluser]Kraig[/eluser]
Because I am using AJAX on a select input...once the user selects a category the new list will be populated with the appropriate pagination. However, since I have that function in my home controller (which has a template that loads on index) I can't reload the template along with the test.php page (test.php shows the results). So when I click on one of the links it loads test.php like the function specifies..unfortunately it loses the template at the same time. I've moved things around, but I can't seem to get it to work.

My AJAX open:
Code:
xmlhttp.open("POST","home/catSelector",true);

My controller function:
Code:
public function catSelector()
{
  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
   $catID = $_POST['cat'];
  }else{
   $catID = 0;
  }
  
  // Pagination!!!
  $data['things'] = $this->membership_model->cat_page($catID);

  $config['base_url'] = base_url().'home/catSelector';
  $config['total_rows'] = $this->membership_model->num_rows;
  $config['per_page'] = 5;
  $this->pagination->initialize($config);
  
  $data['pagination'] =  $this->pagination->create_links();
  //echo $this->membership_model->num_rows;
  $this->load->view('test', $data);
}

Notice how I need to load test.php, because it will display the results..doing this only loads that page and throws out my template even though I'm still at home.php. When I click on a page link I get ( http://localhost:8888/ci/home/catSelector/5 )
test.php:
Code:
<table cellspacing="0" cellpadding="0">
        <tr>
            <th width="50%">File Name:</th>
            <th width="30%">File Size:</th>
            <th>Download Link:</th>
        </tr>
        
        &lt;?php
        $c = true;
  foreach($things as $files){
  
    if ($files['size'] >= 1000000000) {
                $files['size'] = round( ($files['size'] / 1000000000) , 2).' GB';
             }
    if ($files['size'] >= 1000000) {
     $files['size'] = round( ($files['size'] / 1000000) , 2).' MB';
    }else{
    $files['size'] = round( ($files['size'] / 1000) , 2).' KB';
    }
  
   echo '<tr'.(($c = !$c)?' class="odd"':'').">
    <td>$files[name]</td>
    <td>$files[size]</td>
    <td><a href='$files[location]'>Download</a></td>
   </tr>";
  } ?&gt;
        
     </table><br />
&lt;?php echo $pagination; ?&gt;
#6

[eluser]DarkManX[/eluser]
As i told you, you got to redesign your app:

create a method in the controller something like get_products() which will return the table filled with data. and something like show_products(), that will use get_products() to display the talbe wrapped in pagination and other stuff you need.
#7

[eluser]Kraig[/eluser]
That's my question....how can show_products use get_products if get_products has already loaded a view?
#8

[eluser]DarkManX[/eluser]
Code:
public function show_products(){
  // stuff before data table like pagination output etc
  $this->get_products();
  // stuff after data table
}

Just use the method inside of the other method.
#9

[eluser]Kraig[/eluser]
I've tried and tried...everything I do does either of the three; reloads the template so I get a double, only loads test.php, or without clicking the links it displays like it should. I've even tried by getting rid of the template and putting the load views in the home view, but that was also unsuccessful. The concept seems really easy, but I can't get it done for the life of me!!
#10

[eluser]DarkManX[/eluser]
Code:
function get_products(){
$data = // get the product data considering the page for limits etc
$this->load->view('table_data',$data);
}
function show_products(){
$this->load->view('header');
$this->get_products();
$this->load->footer('footer');
}

by clicking on the pagination link you gotta send an ajax request to controller/get_products attaching the page (for limit in query and other stuff) and replacing the whole table_data array by the return of this ajax request.




Theme © iAndrew 2016 - Forum software by © MyBB