0

What will be the rules for my pretty url if I have the following scenario:

links like this where parameters may vary.

 domain/?bt=<token>&e=<email>     

or

 domain/?lt=<token>&e=<email>

then should be processed in a controller/action. ie. mycontroller/get

Also, parameters should be accessible by $_GET inside the action.

ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
brt305
  • 7
  • 1
  • 5
  • whta do you mean with bt or lt? .. what's the difference between the two sample ?... show a real sample of what you need .. – ScaisEdge Nov 05 '17 at 15:25
  • http://localhost:8080/myapplication/web/index.php?r=open-msg/get&bt=123&e=myemail@gmail.com or http://localhost:8080/myapplication/web/index.php?r=click/get&bt=456&e=myemail@gmail.com bt and lt are just parameters. with that links, I want it to be processed to mycontroller/get – brt305 Nov 05 '17 at 15:30

2 Answers2

0

the simplest way is based on the use of urlHelper

use yii\helpers\Url;

$myUrl  = Url::to(['your_controller/your_action', 'bt' => 123, 'e' => 'myemail@gmail.com']);

Using the urlHelper function Url::to .. the url you need is properly formed depending of the urlManager configuration you have set in your config file and the param a manager as show in the sample like entry in an array.

The post or get method is related to the type of metho you have in your ulr call if not other values are specified the url is formed as a get
and you can obtain the values you need in $_GET['bt'] and $_get['e']

http://www.yiiframework.com/doc-2.0/yii-helpers-url.html

http://www.yiiframework.com/doc-2.0/yii-web-urlmanager.html

http://www.yiiframework.com/doc-2.0/guide-runtime-routing.html

ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
0
'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
            '<controller:\w+>/<id:\d+>' => '<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
            '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
            '' => 'call-backs/get',
            'unsubscribes' => 'unsubscribes/get',
        ],
    ],

@scaisEdge, thank you for answering my question. maybe my question isn't that clear but this is the solution I made for my question after a hard find of clues and tips online.

All I wanted was that when a user clicks on a link, hitting the main page/main domain, it will go to my yii project (intended to be a webservice or an API like one) then will be handled by a precise controller and action.

'' => 'call-backs/get'

the code above answers the question. Cheers.

brt305
  • 7
  • 1
  • 5