Creating dynamic pages with url: www.example.com/pageName

Hi

In my system, users need to have their profile pages. It is requested from me that these pages will be displayed in url like this:


www.example.com/John-Doe

,


www.example.com/Mary-Smith

First, how would you create and store these pages in database ?

Second how to achieve these urls in yii2 ?

urls like this: www.example.com/profile/view?id=1 are not an option.

Looking forward to see your answers.

"First, how would you create and store these pages in database ?" That is too big a question with too little detail to answer here.

"Second how to achieve these urls in yii2 " - this is easily achievable using Yii routing via the urlManager component. http://www.yiiframework.com/doc-2.0/guide-runtime-routing.html.

I am doing something similar(ish) where I have example.com/1/ where 1 is a clientid. Here is an extract from my config




	'components' => [

		'urlManager' => [

			'enablePrettyUrl'     => true,

			'showScriptName'      => false,

			'enableStrictParsing' => false,

			'rules' => [

				[

					'pattern'  => '<clientid:\d+>/<controller:\w+>/<action:\w+>/<id:\d+>',

					'route'    => '<controller>/<action>',

					'defaults' => ['clientid' => null],

				],




In this example, if there is a clientid in the url it will populate the clientid variable that I can check/get with Yii::$app->request->get(‘clientid’, null);

So let’s say that I want to replace your clientId with clientUsername, and username is John Doe in database, can I somehow force url to be example.com/John-Doe ( while user/view?id=1 or user/view?name=John+Doe is the real route ) ? I do not fully understand this regex pattern :o

Or maybe there is some other way of doing this better ?