• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
This is a bug or feature ?

#1
Exclamation 
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 ?
I would change this world, but God doesn't give me the source.
Reply

#2
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/CodeIgnit...aceholders
Reply

#3
(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/CodeIgnit...aceholders

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  =====-->
}); 
I would change this world, but God doesn't give me the source.
Reply

#4
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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#5
(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
I would change this world, but God doesn't give me the source.
Reply

#6
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 ?
I would change this world, but God doesn't give me the source.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.