hai all,
how change this url
index.php/dev/index?id=2
to
index.php/custom-own-url
in yii2
Thank you
hai all,
how change this url
index.php/dev/index?id=2
to
index.php/custom-own-url
in yii2
Thank you
By using http://www.yiiframework.com/doc-2.0/yii-web-urlrule.html#$defaults-detail:
[
'route' => 'dev/index',
'pattern' => 'custom-own-url',
'defaults' => [
'id' => 2,
],
]
Or by using a slug if you need to support multiple URLs.
sorry, I do not know how you mean do "slug to support multiple URLs", But i want this configuration is stored in the database and how I call this(configurasion)of the database to main.php ?
Ah. Then:
Introduce extra field called "slug".
When saving a record either ask for it or generate automatically with http://www.yiiframework.com/doc-2.0/yii-behaviors-sluggablebehavior.html.
In rules:
'<slug>' => 'dev/index'
public function actionIndex($slug)
{
$model = MyModel::find()->where(['slug' => $slug])->one();
// ...
}
o… i know u mean, thank you so much for all, i like this forum
hai me again
i have change main urlManager to
'<slug>' => 'dev/index'
and in my view
echo Url::to(['dev/index', 'slug' => '/makan/ayam/berdua-bareng-makan']);
this view print
index.php/%2Fmakan%2Fayam%2Fberdua-bareng-makan
how make this view print like this
index.php/makan/ayam/berdua-bareng-makan
thank you anyway
It won’t since parameter is not path so / should be encoded according to URI RFC.