CodeIgniter Pagination with number in the middle of the query string - codeigniter

I searched the whole day for any solution but did not found any.
I have the same problem as this guy here: Codeigniter Pagination having page number in the middle of url but the "uri_segment" param doesn't work.
My Urls look like:
localhost/controller/0/some/filter/here/
The Pagination returns teh correct link for the next and 2. page.
But once I go there, I get a wrong link back to the first site.
I did something like this:
/*Paginartion Config*/
$pagconfig['base_url'] = base_url($this->uri->segment(1).'/0/'.$this->uri->segment(3).'/'.$this->uri->segment(4).'/'.$this->uri->segment(5).'/'.$this->uri->segment(6).'/'.$this->uri->segment(7).'/'.$this->uri->segment(8));
$pagconfig['total_rows'] = $ress->num_rows;
$pagconfig['per_page'] = 10;
$pagconfig['uri_segment'] = 2;
$pagconfig['prefix'] = '/'.$this->uri->segment(1).'/';
$pagconfig['suffix'] = '/'.$this->uri->segment(3).'/'.$this->uri->segment(4).'/'.$this->uri->segment(5).'/'.$this->uri->segment(6).'/'.$this->uri->segment(7).'/'.$this->uri->segment(8);
Also I just tried using the current_url() as base_url config param and of course I also just tried to use uri_segment = 2 without using pre- and sufix.
It never worked properly.
Routes look like this:
$route['map/(:num)/(:any)'] = 'map/index/$1/$2';
$route['map/(:num)/(:any)/(:any)'] = 'map/index/$1/$2/$3';
$route['map/(:num)/(:any)/(:any)/(:any)'] = 'map/index/$1/$2/$3/$4';
$route['karte/(:num)/(:any)'] = 'map/index/$1/$2';
$route['karte/(:num)/(:any)/(:any)'] = 'map/index/$1/$2/$3';
$route['karte/(:num)/(:any)/(:any)/(:any)'] = 'map/index/$1/$2/$3/$4';
As you can see I use two kind of routes, translates for google.
The routes and Controller also work!
If I type in by hand I get the correct paginated site content:
For Example: localhost/controller/10/some/filter/here returns every row beginning with 11 (it skips first 10 as it should).
Very important is that the number always appears even on the first page where it is 0 - as you can see above.
It would be so great to get any help in that one...
Best Regards

Related

How can I change name of dynamically generated URL in Codeigniter

I'm having dynamic url for my each search result in Codeigniter, but I want to know how can I change my url. For example right now I'm having the url something like this:
www.xyz.com/vendor/vendor_details?iuL80rpoEMxCi89uK6rIyTgqCGuagQ+BUoUnvyBdx09EawMiFfnaB+q3Q8YyBSFwbOVw8+32ZInJrjE2I42teA==
but I want it like this:
www.xyz.com/Delhi/Balaji-Courier-And-Cargo-Bharat-Singh-Market-Opposite-B-7-Petrol-Pump-Vasant-Kunj/011P1238505881A9D9W7_BZDET?xid=RGVsaGkgSW50ZXJuYXRpb25hbCBDb3VyaWVyIFNlcnZpY2VzIEhhbWlsdG9uIFJvYWQ=
here the example
$route['vendor/(:any)/(:any)/(:any)'] = 'vendor/vendor_details/$3';
See this Documentation here: routing
You want to add
www.example.com/city/address/related_id
This Example can help you to get that.
Here are a few routing examples:
$route['journals'] = 'blogs';
A URL containing the word “journals” in the first segment will be remapped to the “blogs” class.
$route[blog/Joe'] = 'blogs/users/34';
A URL containing the segments blog/Joe will be remapped to the “blogs” class and the “users” method. The ID will be set to “34”.
$route['product/(:any)'] = 'catalog/product_lookup';
A URL with “product” as the first segment and anything in the second will be remapped to the “catalog” class and the “product_lookup” method.
$route['product/(:num)'] = 'catalog/product_lookup_by_id/$1';
A URL with “product” as the first segment and a number in the second will be remapped to the “catalog” class and the “product_lookup_by_id” method passing in the match as a variable to the method.

Codeigniter get parameters from url

I have a url "http://localhost/codeigniter/index.php/manual_export/". I need to get last segment from the url which is suppose to be a id. So for example "http://localhost/codeigniter/index.php/manual_export/2". I need to get the last segment which is "2".
I tired to use following code:
$id = end($this->uri->segment_array());
This works when I don't add "2" to the url and gives me "manual_export". However when I pass the id to the url I get an error "The page you requested was not found.". I think this is to do with routing. How can I fix this error.
the other way to do it is by defining a route, it will then be converted to a param
so for example if your controller is called manual_export and the method is getrecord
in the file application/routes.php
$route['manual_export/(:any)'] = "manual_export/getrecord/$1";
in your controller manual_export
function getrecord($id){ // etc etc }
You should use:
$this->uri->segment(n);//in your case n == 2 count starts just after index.php
Docs.

Append variables to URL after pagination's '/page/x'

I'm using a couple URI variables to handle sorting a table, like this
.../page/7/sortby/serial_number/orderby/desc
as you can see, I'm also using the built in CI pagination library. My problem right now is that the links created with $this->pagination->create_links(); strip off sorting variables from the URI, making it difficult to maintain these sorting options between pages.
How can I go about appending these variables sortby/foo/orderby/bar to the URI of links created by the pagination library?
You can use the base_url option, and the page number segments will have to be last. It's a little annoying, but I think it's the simplest way.
// Get the current url segments
$segments = $this->uri->uri_to_assoc();
// Unset the "page" segment so it's not there twice
$segments['page'] = null;
// Put the uri back together
$uri = $this->uri->assoc_to_uri($segmenmts);
$config['base_url'] = 'controller/method/'.$uri.'/page/';
// other config here
$this->pagination->initialize($config);
I found the answers thanks to WesleyMurch leading me in the right direction. In order to always have the page variable as the last in the uri (which is necessary when using CI's pagination library), I used this
$totalseg = $this->uri->total_segments();
$config['uri_segment'] = $totalseg;
then following WesleyMurch's idea, I rebuilt the base_url,
$segments = $this->uri->uri_to_assoc();
unset($segments['page']); //so page doesn't show up twice
$uri = $this->uri->assoc_to_uri($segments);
$config['base_url'] = site_url()."/controller/method/".$uri."/page/";
and of course initialize the pagination with all the correct config options
$this->pagination->initialize($config);
I use the answer of ejfrancis but...
If for some reason the user put not numeric or negative number in the url's page var, i suggest make a validation before set the $config['uri_segment'], like this one:
$totalseg = $this->uri->segment($totalseg)>0 &&
is_numeric($this->uri->segment($totalseg))?
$totalseg : NULL;
I hope it help!

Error when setting new routes in codeigniter

i have an URL: mydomain.com/view/page/about
then i want change it to be: mydomain.com/page/about
i’ve tried add a new routes:
$route[‘page/(:any)’] = ‘view/page/$1’;
but when i refresh my browser, it always show the page in: mydomain.com/view/page/index
any advice to solve my problem?
thank you before
Note that mydomain.com/page won't get you to view/page. Your regexp expects there to be a ending / in the url.
Either do a
$route[‘page/?(:any)’] = ‘view/page/$1’;
Or
$route[‘page’] = ‘view/page’;
$route[‘page/(:any)’] = ‘view/page/$1’;
If you wish to be more accurate.

Bizarre problem with CodeIgniter routing rules

I have set two rules :
$route['followers/(:num)'] = 'hall/filter/subscribers/$1';
And :
$route['see/(:num)'] = 'hall/see/$1';
But while the first one is working all fine, the second one behaves juste like the 2nd argument (the :num) wasn't passed at all (displaying see/4 gives the hall/see/ page, not hall/see/4 !). This is very odd because from my point of view, those 2 routes work the same way !!
Any idea ?
Edit :
If I change $route['see/(:num)'] to $route['foo/see/(:num)'] then it works. This is crazy oO
You should use "" instead '', so it should be
$route['followers/(:num)'] = "hall/filter/subscribers/$1";
$route['see/(:num)'] = "hall/see/$1";

Resources