Au cours du développement, j'ai fait face à un problème avec urlManager.Yii2, paramètre facultatif dans le rounte
J'ai SiteController avec l'action "catégorie".
public function actionCategory($id = null, $city = null, $location = null)
{
echo $id;
echo $city;
echo $location;
}
Toutes les combinaisons possibles qui peuvent être utilisés avec cette action:
id, city, location = null
id, city = null, location
id, city = null, location = null
id = null, city = null, location = null
id = null, city = null, location
Je ne sais pas comment écrire les règles du urlManager, après que je vais obtenir les valeurs suivantes dans les variables après appuyez sur les liens:
<h4><?= Html::a('ID City', ['/site/category', 'id' => 'barbershop', 'city' => 'Praha'], ['class' => 'btn btn-primary']) ?></h4>
The return value from "category" action:
id = 'barbershop'
city = 'Praha'
location = ''
<h4><?= Html::a('ID Location', ['/site/category', 'id' => 'barbershop', 'location' => '23,65'], ['class' => 'btn btn-primary']) ?></h4>
The return value from "category" action:
id = 'barbershop'
city = ''
location = '23,65'
<h4><?= Html::a('ID', ['/site/category', 'id' => 'barbershop'], ['class' => 'btn btn-primary']) ?></h4>
The return value from "category" action:
id = 'barbershop'
city = ''
location = ''
<h4><?= Html::a('City', ['/site/category', 'city' => 'Praha'], ['class' => 'btn btn-primary']) ?></h4>
The return value from "category" action:
id = ''
city = 'Praha'
location = ''
<h4><?= Html::a('Location', ['/site/category', 'location' => '14,23'], ['class' => 'btn btn-primary']) ?></h4>
The return value from "category" action:
id = ''
city = ''
location = '14,23'
Voulez-vous m'aider avec ce problème?