0

я хочу получить что то вроде этого http://sitename.com/controllername/actionname/getname/getvalue более конкретно http://sitename.com/product/index/id/12

и уже в контроллере Product получить значение id

<?php
namespace frontend\controllers;

use yii\web\Controller;

class ProductController extends Controller
{
    public function actionIndex($id){
        echo $id; //равно 12
    }
}

самое главное сохранить названиe id в Url http://sitename.com/product/index/**id**/12

заранее спасибо

1 ответ 1

0

Для того, чтоб получились красивые урлы, вам необходимо изменить параметры компонента urlManager. в конфиг файле

'components' => [
'urlManager' => [
    'class' => 'yii\web\UrlManager',
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'rules' => [
        ['pattern' => 'product/index/id/<id: \d+>', 'route' => 'product/index'],
        ... // еще правила
    ],
]

]

подробности https://yiiframework.com.ua/ru/doc/guide/2/runtime-routing/#url-rules

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.