Comments (13)
Why do you use $params = !empty($_GET) ? '?'.http_build_query($_GET) : '';
? This will obviously create the ?slug=...
part of the URL.
from yii2-localeurls.
Also look at #57 where a similar issue was reported. I've since added test cases that show, that URL creation with slugs works just fine. Check the UrlCreationTest
and SlugRedirectTest
where this is tested.
from yii2-localeurls.
Ok, I think this is a problem with your URL rules.
First in your rule '<controller:\w+>/<action:\w+>/<slug:[A-Za-z0-9 -_.]+>' => '<controller>/<action:\w+>/slug'
you should not have :\w+
in the action part on the right side. Also that slug
doesn't really belong there.
You should also put the more specific rules on top, because when parsing a request, the first matching rule will be used.
I've done a test here and everything works as expected. My configuration is:
[
'language' => 'en',
'components' => [
'urlManager' => [
'class' => 'codemix\localeurls\UrlManager',
'languages' => ['en','de','fr'],
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller:\w+>/<action:\w+>/<slug:[A-Za-z0-9 -_.]+>' => '<controller>/<action>',
],
],
...
]
I have a simple test action in my SiteController
like:
public function actionDemo($slug)
{
return $this->render('index');
}
And I've used the LanguageDropdown
as shown in the README.
If I go to site/demo/some-slug
the page will render fine and the dropdown will have links like
/de/site/demo/some-slug
/fr/site/demo/some-slug
from yii2-localeurls.
Thanks for your quick response.the problem is with language switcher i made as you said
i have 2 languages so i need a simple switcher .
$route = Yii::$app->controller->route;
$params = $_GET;
array_unshift($params, '/'.$route);
<?php if(Yii::$app->language == 'ar'){ ?>
<?= Html::a('English', [Yii::$app->urlManager->createUrl($params), 'language'=>'en']); ?>
<?php }else{?>
<?= Html::a('Arabic', [Yii::$app->urlManager->createUrl($params), 'language'=>'ar']); } ?>
i tried part of the code taken from your language drop down its not working .its producing url like below
http://localhost/multi/backend/web/en/multi/backend/web/ar/post/slug?slug=my-long-slug-post
from yii2-localeurls.
Again, I'm pretty sure, this is a problem with your URL rules. So please first try to make it work without the localeurl extension (i.e. remove the codemix\localeurls\UrlManager
and according configuration). You need to be able to create a slug URL with \yii\helpers\Url::to(['your/action', 'slug' =>'some-slug'])
. This doesn't work with the rules you have.
I'm closing this for now, because I can't reproduce any issue. If you find out, that URL creation works correctly without our class but fails with localeurls let us know and I will have another look.
from yii2-localeurls.
Thanks...
i tried everything nothing suceed this is the site i developed using yii2 used above default urlrule
http://flywingzdestination.com/package/malaysia-3-nights-4-days
i just need a simple switcher when we are in English site show a switcher link like Arabic and viceversa.the problem is i'm generating the url its like
http://localhost/**multi/backend/web**/en/**multi/backend/web**/ar/post/slug?slug=my-long-slug-post
as explained just above my post
i dont know why its repeating the multi/backend/web
past 2 days i'm with this without any luck for this simple switcher
from yii2-localeurls.
Can you create a correct slug URL without our extension?
from yii2-localeurls.
hii after lot of trying i got solution for my first problem
$route = Yii::$app->controller->route;
if(Yii::$app->language == 'ar'){
$_GET['language'] = 'en';
}else{
$_GET['language'] = 'ar';
}
$params = $_GET;
array_unshift($params, '/'.$route);
and for link
<?php if(Yii::$app->language == 'ar'){ ?>
<?= Html::a('English', Yii::$app->urlManager->createUrl($params)); ?>
<?php }else{?>
<?= Html::a('Arabic', Yii::$app->urlManager->createUrl($params)); } ?>
Now i have one more problem.I cant hide action name when using slug
i cant use url like this
http://localhost/multi/backend/web/ar/post/my-long-slug-post
when switch it'll redirect to
http://localhost/multi/backend/web/post/slug?slug=my-long-slug-post
.But when i use default Url manager it works fine using below rules
'<controller:\w+>/<slug:[A-Za-z0-9 -_.]+>' => '<controller>/slug',
and you can see the live example used above rule
http://flywingzdestination.com/package/malaysia-3-nights-4-days
from yii2-localeurls.
@vc7deo Hmm. Can you provide a simple test configuration that I can use to reproduce the issue? Preferably you should use a clean, simple fresh yii application and only add so much configuration there until the problem appears. Then post what you've changed in the default configuration here.
from yii2-localeurls.
@mikehaertl .. i use fresh yii2 application for this.Here is my Urlmanager configuration.When i comment first 3 lines it works perfectly.
'urlManager' => [
'class' => 'codemix\localeurls\UrlManager',
'languages' => ['en', 'ar'],
'enableDefaultLanguageUrlCode' => false,
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<alias:index|login>' => 'site/<alias>',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>/<slug:[A-Za-z0-9 -_.]+>' => '<controller>/<action>',
'<controller:\w+>/<slug:[A-Za-z0-9 -_.]+>' => '<controller>/slug',
'defaultRoute' => '/site/index',
],
],
from yii2-localeurls.
This is still a problem with your URL rules. The following 2 rules match the same URL format:
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'<controller:\w+>/<slug:[A-Za-z0-9 -_.]+>' => '<controller>/slug',
When you create a URL, Yii will go through all URL rules and use the first matching rule. So for example:
$url = Url::to(['somecontroller/slug', 'slug' => 'blabla'])
The first rule that matches the route is <controller:\w+>/<action:\w+>
. Yii will stop there and use this rule. You need to make sure, that your URL rules are unambiguous and that more special rules are listed first.
All this has nothing to do with this extension. I'd suggest that you carefully read again about URL creation and parsing in the Yii guide here: http://www.yiiframework.com/doc-2.0/guide-runtime-routing.html
from yii2-localeurls.
@mikehaertl .. as i said before its working with default urlmanager
i used same url rules the below live site
this is controller without action(controller/slug)
http://flywingzdestination.com/package/malaysia-3-nights-4-days
and this controller with action
http://flywingzdestination.com/site/contact
both working perfectly
if i use controller/action/slug then this urlmanager works.but it would be better if i can hide the action from it
from yii2-localeurls.
I'm still missing the code you used to create the URL. The URL itself doesn't help me to debug your problem.
from yii2-localeurls.
Related Issues (20)
- Problem with default language HOT 3
- Redirect from https to http HOT 1
- Ajax also redirects when enableLanguagePersistence is turned on HOT 2
- Regular expression trouble HOT 5
- Using GeoIp as primary language detection method HOT 2
- Support for different domains HOT 2
- The page keeps redirecting HOT 1
- index.php is shown in browser url HOT 1
- How can i change language position in url HOT 2
- Please fix this define HOT 3
- Url::to with rules HOT 1
- One language for all EU locales HOT 1
- Problem with change language under Windows HOT 3
- Some issues with yii2-localeurls
- using Yii functionality HOT 2
- Bug in tests HOT 1
- The configuration for the "localeUrls" component must contain a "class" element. HOT 1
- Generating URL with custom urlRule HOT 2
- Help me please. Error with route. HOT 3
- Redirect for specific languages HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yii2-localeurls.