CodeIgniter Forums
This is a bug or feature ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: This is a bug or feature ? (/showthread.php?tid=74128)



This is a bug or feature ? - Digital_Wolf - 07-26-2019

Hello everyone who reads this topic  Wink 

Helping one man solve his problem with the redirects, I was faced with the problem...
let's say I have this small system routing:

PHP Code:
$routes->group('{locale}', function($routes) {
 
   // Test #1 page
 
   $routes->add('FirstTest''TestController::test_1');
 
   // Test #2 page
 
   $routes->add('SecondTest''TestController::test_2', ['as' => 'Test_2']);
}); 


and in the method "test_1" spelled out the function "return redirect()->route('Test_2')",

then when you go to this route, it redirects to "TestController::test_2" and in the place of the name of the locale in the url is this entry: "%7Blocale%7D" and segmet "/SecondTest"

Q: is This recording supposed to be like this "%7Blocale%7D", or should it be the localization we were originally in ?


RE: This is a bug or feature ? - MGatner - 07-28-2019

Docs state:

“ {locale} cannot be used as a placeholder or other part of the route, as it is reserved for use in localization.”

So my guess is that the explicit reference is bugging the named route. Not sure how to accomplish what you’re after other than leaving out the group maybe?

Ref https://codeigniter4.github.io/CodeIgniter4/incoming/routing.html#placeholders


RE: This is a bug or feature ? - Digital_Wolf - 07-28-2019

(07-28-2019, 07:52 AM)MGatner Wrote: Docs state:

“ {locale} cannot be used as a placeholder or other part of the route, as it is reserved for use in localization.”

So my guess is that the explicit reference is bugging the named route. Not sure how to accomplish what you’re after other than leaving out the group maybe?

Ref https://codeigniter4.github.io/CodeIgniter4/incoming/routing.html#placeholders

I don't quite understand, then it turns out this section (which you refer to) contradicts that:
{locale} in routes

How can I then implement such a system:
I have a variable:
$baseLocale = 'en';
$supportedLocales = ['en', 'ru'];

and I want to have routes like:
https://example.com/(EN or RU)/auth/(SignIN or SignUP)/

But so that these routes were logically linked using groups, like in my example above...

now I have here such code at myself in the file of a route.PHP:

PHP Code:
$routes->group('{locale}', function($routes) {
 
 //  Auth system
 
 $routes->group('auth', function($routes) {
 
    $routes->add('welcome''AuthController::welcome');
 
    $routes->add('signup''AuthController::s_up');
 
    $routes->add('signin''AuthController::s_in');
 
 });
 
 //  Other system  =====-->
}); 



RE: This is a bug or feature ? - InsiteFX - 07-28-2019

PHP Code:
// Config/App.php
public $defaultLocale 'en';

public 
$negotiateLocale true;

// in controller
$locale $this->request->getLocale();

// or
$locale service('request')->getLocale(); 

It's doing that because you may not have set the default locale by using getLocale() method.


RE: This is a bug or feature ? - Digital_Wolf - 07-28-2019

(07-28-2019, 10:53 AM)InsiteFX Wrote:
PHP Code:
// Config/App.php
public $defaultLocale 'en';

public 
$negotiateLocale true;

// in controller
$locale $this->request->getLocale();

// or
$locale service('request')->getLocale(); 

Uh no, I have in config/App.php all this has long been installed,
but that's what I do not have in the controller so this is this function:

PHP Code:
$locale $this->request->getLocale(); 

in place of it I have this:

PHP Code:
$data = [
 
 'Head' => [
 
    'Lang' => $this->request->getLocale(),
 
    'Title' => 'Authentication'
 
 ],
 
 'Body' => [],
 
 'Foot' => []
];
//  Call vews with data transfer
echo view('templates/header'$data['Head']);
... 
Other code...
// Data cleaning
unset($data); 

In my case, this variable: $data['Head']; Called in

Code:
<html lang="<?= $Lang; ?>">

And when I follow the link from example.com/EN/auth/welcome to example.com/EN/auth/signup
that at me everything is perfectly displayed, but if I in a method "signup" of the controller "Auth" call function "return redirect()->route('Welcome')", and then I update the page, then at me instead of example.com/EN/auth/welcome the browser bar appears example.com/%7Blocale%7D/auth/welcome


RE: This is a bug or feature ? - Digital_Wolf - 07-28-2019

UPD: I do not quite understand why to use the variable $locale,
because it is of little use, as I directly transmit this value to the views and there is already as I said before can just use:
Code:
<= lang(head.namePageAuth_welcome, $Lang); ?>
or
<html lang="<?= $Lang; ?>">
or somewhere she have it tracking in system code ?