This is an email activation link written in user controller
http://www.some.com/user/activate_user/user#gmail.com/90101001010
I want to write routes for this.
I tried the below one but its
// USER POST
$route['user'] = 'user';
$route['user/activate_user/:any/:num'] = 'user/activate_user/$1/$2';
Error
An Error Was Encountered
The URI you submitted has disallowed characters.
if i run uri like this it's fine
http://www.some.com/user/activate_user/activate_user/1111/90101001010
why is it not accepting email id?
should be:
$route['user/([\w+-]+)(\.[\w+-]+)*#([a-zA-Z\d-]+\.)+[a-zA-Z]{2,6}/(:any)']
The entire string is a regex without delimiters or modifiers. You were putting delimiters, modifiers and were also using ^ and $.
Please check your config file, which uri chars are you permitted in the url. by default it is look likes:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_-';
if you want further need please visit the link Url Guideline by ellislab
This worked
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_#-';
$route['user/activate_user/(:any)/(:any)'] = 'user/activate_user/$1/$2'; –
Go to config.php
Find $config['permitted_uri_chars'] = 'a-z 0-9~%.:_-';
And add $config['permitted_uri_chars'] = 'a-z 0-9~%.:_()#&\-!';
And the stop and or refresh server
Replace This
$route['user'] = 'user';
$route['user/activate_user/:any/:num'] = 'user/activate_user/$1/$2';
With This
$route['user'] = 'user';
$route['user/activate_user/(:any)/(:any)'] = 'user/activate_user/$1/$2';
Added
Tutorial Email Activation
This worked for me
config.php
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_#-';
router.php
$route['user/activate_user/(:any)/(:any)'] = 'user/activate_user/$1/$2';
Related
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;
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!
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.
For my Rest WebService I need some variations to put the city or Region or something else in it. So my URI should look like this:
/rest/rating/locations?city=London
Now I'm using following functions to get the last URI Segment:
$segcount = $this->uri->total_segments();
$lastseg = $this->uri->segment($segcount);
The Problem is here that everthing from the Question Mark gets cutted!
The variable which gets saved is just: locations
I've tried configure following in the config.php:
$config['uri_protocol'] = 'PATH_INFO';
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-?';
$config['enable_query_strings'] = TRUE;
Is there any other possibility to save the whole segment with the question mark?
First, make sure you have:
$config['allow_get_array'] = TRUE;
enable_query_strings is actually something else entirely, an old feature that's not used much.
The URI class still won't help you here, you'll have to refer to the query string separately.
$segcount = $this->uri->total_segments();
$lastseg = $this->uri->segment($segcount);
// Either of these should work
$query_string = http_build_query($this->input->get());
$query_string = $this->input->server('QUERY_STRING');
$lastseg_with_query = $lastseg.'?'.$query_string;
In your config file, make sure the following is set as TRUE:
$config['allow_get_array']= TRUE;
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.