REST Url Manager


(Dannythebestguy) #1

Can somebody show what should I do to add the additional employees parameters to the company Activecontroller.

/companies/3/employees/45

I have a company controller, with byEmployee($employeeID) action.

I want to extract the details of employee 45 working in company 3.

Which I can easily do in regular controller with :

http:://localhost/frontend/web/index.php?r=company/byEmployee&cid=3&eid=45


(Alirz23) #2

you need to enable the urlManager and add rule for that route


'urlManager' => [

            'enablePrettyUrl' => true,

            'showScriptName' => false,

            'rules' => [

                '<companies:[\w+]>/<companyid:[\d+]>/<employees:[\w+]>/<employeeid: [\d+]>' => '<controllerName>/<actionName>'

            ],

        ],