I have a problem with codeigniter and cyrilc url I'm trying to do something like this,
site.com/home
site.com/начало
in my router I've got
$route['([А-Яа-яa-zA-Z0-9-]+)'] = "home/index/$1";
Which dosn't work I put in my config.php and
$config['permitted_uri_chars'] = 'a-zа-яё 0-9~%.:_\-';
but still dosn't work then I found in internet
$route['(:any+)(?:(.html))?'] = "home/page/$1";
Which is working but, now I lose my router native behavior because :any gives and /
so Is there a way to use (:any) but not actually any, so I can keep my router behavior
Thank you in advance
Related
This is my routes setup code
$route['general/(:any)'] = "videos/filter/$1/1";
$route['general/(:any)/(:num)'] = "videos/filter/$1/1/$2"; //pagination
Following link works fine.
www.example.com/general/latest
But below link doesn't work like what i want
www.example.com/general/latest-trending/5
$route['general/(:any)'] only executes always.
How to solve this issue?
Reverse the order:
$route['general/(:any)/(:num)'] = "videos/filter/$1/1/$2"; //pagination
$route['general/(:any)'] = "videos/filter/$1/1";
You want more specific routes first, because if the shorter one matches first, it will ignore all other routes.
I had my users profile at
www.domain.com/user/username
and moved it at
www.domain.com/username
but this required to add most classes functions into the routes.php file in the config and if i want to add new features to my app i will need to add all the functions into the routes.php file which doesnt sound good practice...
What is the best way that other deal with it on CodeIgniter ?
Perhaps, you can do it the other way round - make a whitelist of usernames that can't be taken (those would be names of your controllers, like admin, contact, etc...) and route anything except the whitelist items.
seems i got the answer
what i did is add the below code for every controller i have
$route['controller'] = "controller";
$route['controller/(:any)'] = "controller/$1";
and this code at the bottom
$route['(:any)'] = "user/$1";
I'm making this little project in Codeigniter and I need to have one additional segment before controller.
The default Codeigniter URL is:
base_url/controller/function/parameter1/../parametern
What I need is:
base_url/something/controller/function/parameter1/../parametern
Where "something" is a name that user creates so I cant create a subfolder in controllers folder as suggested in other topics because its dynamic and each user chooses what he likes.
Basically what I need is that it like ignores that segment (I would catch that segment in a hook, extend CI_controller or something like that and validate it), for example if I write base_url/stackoverflow-rocks/home/function, base_url/asd-whatever/home/function Codeigniter would look at it like base_url/home/function
I have also looked at Passing variables before controller URI segment in CodeIgniter question, its almost the same as mine but the suggested answer didn't work.
I used $route['(:any)/(:any)'] = '$2'; which works if the url is base_url/whatever/home, but if the url is base_url/whatever/home/function or base_url/whatever/home/function/param1/../paramn it doesn't, the workaround for this is to write:
$route['(:any)/(:any)'] = '$2';
$route['(:any)/(:any)/(:any)'] = '$2/$3';
...
$route['(:any)/../(:any)'] = '$2/../$n'
which is easy, but seems a bit lame, and it will only work if I have from 2 to n segments in url. I also tried to mix it with regular expressions, like:
$route['(:any)/(.*)'] = '$2'
But it works just like the previous one, (.*) is just one segment but not the whole url...
Is there some way to just write
$route['(:any)/rest of the url'] = 'rest of the url';?
I also tried using .htaccess:
RewriteRule ([^/]*)/(.*) inedx.php?/$2
or
RewriteRule (.*)/(.*) index.php?/$2
But it didn't work because $2 referenced to the first part, for example if I write:
base_url/one/two it rewrites it to base_url/index.php?/one.
But if I use:
RewriteRule (.*)/(.*) index.php?/$1/test/$2
it references as it should, for example base_url/one/two => base_url/index.php?/one/test/two, so $1 = one and $2 = two, as it should be.
Quite a long question but I hope someone can help, thanks!
see if this works:
$route['base_url/controller/(:any)'] = 'base_url/$1'
I am trying to work out the code igniter routing
I have a url that will look like
http://example.com/register
I want that to hit
http://example.com/account/register/normal
I also have
http://example.com/invite/something_random_here
which I want to hit
http://example.com/account/register/invite/something_random_here
I also have
http://example.com/register/something_random_here
which I want to hit
http://example.com/account/register/subscribed/something_random_here
How do I setup these routes?
Pretty much Straight out of the User Guide
$route['register'] = "account/register/normal";
$route['invite/(:any)'] = "account/register/invite/$1";
Basically anything after invite/ will get tacked onto the end of account/register/invite. I believe it only works for one segment, if you want multiple segment support you'll have to use a regular expression:
$route['invite/(.+)'] = "account/register/invite/$1";
Another usefull one (because I believe (:any) only works for characters) would be:
$route['invite/([a-zA-Z0-9_-]+)'] = "account/register/invite/$1";
This will let all alpha-numeric values (single segment) with _ or - go through, great for GUIDs :)
I believe for your first URL, you would use the following route:
$route['register'] = "account/register/normal";
Your second URL, would make use of the following route:
$route['invite/(:any)'] = "account/register/invite/$1";
Both of these routes would need to be placed in your "config/routes.php" file.
Hope this helps?
I understand that CI is mostly URL segment based, but I want to have a query string: blahblah.com/search.html?q=keyword
When I try $this->input->get( "q" ), it returns empty. Is there a route or something I need to configure?
Why not make it http://mysite.com/search/keyword/
You have to enable query strings
CodeIgniter optionally supports this capability, which can be enabled in your application/config.php file. If you open your config file you'll see these items:
$config['enable_query_strings'] =
FALSE;$config['controller_trigger'] =
'c'; $config['function_trigger'] =
'm';
If you change "enable_query_strings" to TRUE this feature will become active. Your controllers and functions will then be accessible using the "trigger" words you've set to invoke your controllers and methods:
index.php?c=controller&m=method
Example: index.php?c=products&m=view&id=345
http://codeigniter.com/user_guide/general/urls.html
The best way to get query strings working in CodeIgniter is to use Google. This question is asked (and answered) on the forums, here and on twitter at least 10 times a day.
There are a few methods, but recently I am a fan of the following method:
http://www.dijexi.com/2009/08/how-to-mix-segment-and-query-string-in-codeigniter/
I prefer this over others as it will have no application-wide effects like some other approaches and it won't require any crazy hacking to get it working.
If you want this $_GET support throughout the entire app, just put the parse_str into MY_Controller or a pre_controller hook.