Locustv2 / yii2-encode-url-rule

Makes the encoding of query parameters easier when creating urls
BSD 3-Clause "New" or "Revised" License
5 stars 2 forks source link

Why is it better than regular array parameters #1

Open samdark opened 7 years ago

samdark commented 7 years ago

Hello!

Array parameters could be passed via http://example.com?x[]=1&x[]=2. I'm not sure what's the purpose of the extension considering the fact...

Locustv2 commented 7 years ago

This extension is more about passing multiple parameters as a single parameter in the url. And this does not affect the usage of the parameters in action arguments or using Yii::$app->request->get().

I created this some years back when i was working with yii1 where i had to also add a layer of encryption using blowfish. But i removed it in this one.

It eases the way to pass parameters when creating urls, for example:

$userAttributes = User::findOne(['id' => 123])->getAttributes(['email', 'status', 'locale', 'code']);

$url = Url::to(['/controller/my-action', '_pi' => $userAttributes]);

And this would provide a url like this /controller/action?_pi=aWQ9MSZmYWNlYm9va0lkPW51bGwmZW1haWw9JTIyYWRtaW4lNDBmb3hzdHJlYWsuY

Can be handy in cases where there is no need for POST action but you also don't want people to play with your urls.

Does not affect action parameters:

public function actionMyAction($email, $status, $locale, $code = null)
{
    var_dump(Yii::$app->request->get());
    var_dump($this->actionParams);
}
samdark commented 7 years ago

Well, that's very very specific use case. Can't imagine a case when this is required.