V.Rashkov
V.Rashkov

Reputation: 1735

Routing cyrillic characters in codeigniter

How to allow the routing of cyrillic characters in codeigniter ?

Upvotes: 1

Views: 1996

Answers (2)

Hop hop
Hop hop

Reputation: 856

Let's say for example you have the following route:

controller/action/someId

Let's Now say your controller you want to be контролер (in cyrillic or any other alphabet, so you get:

контролер/action/someId

Obviously you can not name your Controller class "Контролер", so you must do it trough application/config/routes.php

Sadly if you go there and type:

$route['контролер/action/(:num)'] = "controller/action/$1"; 

to match the route, Codeigniter will NOT use controller but will throw an error.

It took me some time to understand that Codeigniter gets an encoded URL something looking like %5%6%77%24

So to match the encoded string you have to have it encoded also in your routes.php.

You can do that, and keep code readable if you enter the route like that:

$route[rawurlencode('контролер').'/action/(:num)'] = "controller/action/$1"; 

This will encode the part of the URL that's in non-latin characters, you should use that also in links, just to make sure all is parallel and does not fail somewhere along the line so:

<?php echo site_url( rawurlencode('контролер').'/action/'.$id ); ?>

Hope it helps! It worked flawlessly for me : ))

Upvotes: 4

kuboslav
kuboslav

Reputation: 1460

In file application/config/config.php find $config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-'; and add there each one allowed character – for example:

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-абвгдеёжзийклмнопрстуфхцчшщъыьэюя';

Upvotes: 0

Related Questions