Error when setting new routes in codeigniter - 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.

Related

How to get the full URL of the route?

I have a Sinatra template file, which sends a POST request to the route /en/signup (en is the locale).
I need to extract the en from /en/signup. I tried to use request.path in the following code, but contains only /signup, not /en/signup. The log file shows that /en/signup was called.
What construct can I use in the route post '/signup' in order to get /en/signup?
Wake up, Neo.
From route file:
before '/:locale/*' do
I18n.locale = params[:locale]
request.path_info = '/' + params[:splat ][0]
end
That solved my problem: redirect to('/' + I18n.locale.to_s + '/signup-success').
If you can use java:
var url = document.URL;
var pieces = url.split("/");
Then simply split where and when you need to. The variable pieces is an array. For further splitting use pieces = pieces[1 (or others) ].split("/ (or others ");
I hope this helps!
Hello Sir if you use php try the code below. it will get the full path of the url for instance /example/en/signup.
$_SERVER['REQUEST_URI']
In Addition you can get including the http host (localhost) try the code below
$output = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
echo $output;

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.

CodeIgniter Pagination with number in the middle of the query string

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

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";

Codeigniter problem with routes!

I am trying to do this route trick:
$route['cp/roles/:num'] = "cp/roles/index/:num";
but it doesn't work :(
please help me!!
advanced thanks .
According to the documentation on URI Routing:
$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 function.”
So, for your particular instance, you would do the following:
$route['cp/roles/(:num)'] = "cp/roles/index/$1";
You could try
$route['cp/roles/:num'] = "cp/roles";
and then instead of passing a variable in your function you use
$this->uri->segment(3);
or the number that correspond to the segment.

Resources