• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5


I've got some issue with base_url in pagination setup. I want to paginate the two or more weburls: http://www.fotoramik.sk/blog/kategoria/clanky and http://www.fotoramik.sk/blog/kategoria/recenzie When I set the base_url I do it this way


But it's not working correctly, the base_url is "stacking up" so after few clicks, generated links tried to visit http://www.fotoramik.sk/kategoria/clanky/clanky/1 page

What do i do wrong?

First of all, I'd imagine you'd want to be using $this->uri->segment(3), unless of course you have you're own custom URI class. Other than that, it just sounds like the problem is that you're using a relative path in your URLs, instead of an absolute path.

Please could you post the code for your controller method, as I suspect there's a bit more to it than that?

this is the controller's method kategoria which handles the calling of model article.php:

function kategoria()

The third segment is "clanky" or "recenzie" (articles/reviews). "kategoria" is just to determine what kind of output we want in body. (category)

For pagination implementation I've tried to use the example from this article (http://www.devshed.com/c/a/PHP/Paginatin...Igniter/2/)

Article.php model, function body:

function body($page,$category) //page-WHERE klauzula ; kategoria - ide o vypis vsetkych clankov v kategorii?

    $data['popis_logo']="Všetko o digitálnych fotorámikoch";

     /* This block handles different stuff */
    If ($page==""): $data['query']=$this->db->query('SELECT id,odkaz,title,picture,text,date FROM articles WHERE date<=now() ORDER BY id DESC LIMIT 3'); endif;
    If (($page!="") AND ($category=="")): $data['query']=$this->db->query("SELECT id,odkaz,title,picture,text,date FROM articles WHERE odkaz='".$page."' ORDER BY id DESC LIMIT 1"); endif;
    /* end of the block */
    If (($page!="") AND ($category=="kategoria")):
    // set pagination parameters
    $config['base_url']=''; //don't know what to put here
    $this->db->where('kategoria',$page); //counts only articles of category specified in $page var
    $config['full_tag_open']='<div id="paginglinks">';

// create pagination links


If ($this->uri->segment(4)=="") {$current_page="0";} else {$current_page=$this->uri->segment(4);}//If page is not set it puts 0 to limitation

     $data['query']=$this->db->query("SELECT id,odkaz,title,picture,text,date FROM articles WHERE kategoria='".$page."' ORDER BY id DESC LIMIT ".$current_page.",3");

$config['base_url'] would normally be the URL that comes before the page number. For example:
$config['base_url'] = site_url('controller/method/');

Hope this helps.


Check it out - on the bottom, Why does number two referes to http://www.fotoramik.sk/blog/kategoria/clanky/3 ???

The page number you see isn't the page number as such, but rather the result number where the page should start rendering. Say for example, you displayed 20 results page, page 1 would be 1 (as that's the first result), page 2 would be 20 (as that's the first result of the second page), page 3 would be 40, and so on.

EDIT: Basically, you should be able to use this number in your $this->db->limit() statement, but don't forget to limit the results to 3 per page if that's how many results per page you've told the pagination class you want to use.

$start_result = $this->uri->segment(3);
$this->db->limit($start_result, 3);

It doesn't work well, look:

http://www.fotoramik.sk/blog/kategoria/3 this is the url it tries to load after I click "2" on pagination links however there should be http://www.fotoramikl.sk/blog/kategoria/clanky/3 -> "clanky" part is missing (it's variable)

Then you need to add the "clanky" part to your base URL.
$config['base_url'] = site_url('blog/kategoria/clanky');

OK, I've done that but now I got a problem with numbering and showing of the articles.

http://www.fotoramik.sk/ -> when you look here, you can see the "test" article. It's category is "clanky" however when you go to "Clanky", test doesn't show. there are pagination links but the number 2 leads to the 3rd article "Co je to fotoramik?" but test is nowhere.

I forgot... The MySQL limit offset starts at 0, not one. So you'd need to do something like this in your model.
$start_result = $this->uri->segment(3);
$this->db->limit($start_result - 1, 3); // subtract 1

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.