为每个名称生成一个唯一的 link - yii2

Generate a unique link for each name - yii2

我正在开发网络应用程序,用户应该在网络应用程序上注册。
这是我的 table 存储数据的地方 post 注册。

我想给每个用户一个唯一的 url,它将存储在保存用户详细信息的同一 table 中,以便他们的个人资料 url 分享他们的协会名称(society_name)。例如,网站域为 www.example.com and the users' url would be www.example.com/mysociety

我想将唯一生成的 url 保存在我的 table.

字段“url”(#14) 中

我的用户注册控制器看起来像这样

public function actionRegister() {
    $this->layout = 'society';
    
    if (!Yii::$app->user->isGuest) {
        return $this->goHome();
    }

    
    $model = new User();
    $society = new \app\models\Society();
    
    if ($model->load(Yii::$app->request->post())) {
        
    $password= $_POST['User']['password'];
    $password_hash = Yii::$app->security->generatePasswordHash($password);
    $auth_key = Yii::$app->security->generateRandomString();
    
    $mobile=$_POST['User']['mobile'];
    $society = new \app\models\Society();
    $random_number=mt_rand(10000, 99999);
    $society->society_name = $_POST['Society']['society_name'];
    $society->contact_person = $_POST['Society']['contact_person']; 
    $society->address = $_POST['Society']['address'];       
    $society->society_id =$random_number;
    $society->mobile = $mobile;
    $society->status =0;
    $society->save();
    $session = Yii::$app->session;
    return $this->redirect(['regsuccess']);
    }  
    return $this->render('society', [
                'model' => $model,
                'society' => $society,
   ]);}

PS : 英语不是我的母语。我是 yii2 和 Whosebug 的新手,请原谅我的错误。 谢谢

我解决了

Modified my Controller

public function actionRegister() {
$this->layout = 'society';
if (!Yii::$app->user->isGuest) {
    return $this->goHome();
}


$model = new User();
$society = new \app\models\Society();
if ($model->load(Yii::$app->request->post())) {
$password= $_POST['User']['password'];
$password_hash = Yii::$app->security->generatePasswordHash($password);
$auth_key = Yii::$app->security->generateRandomString();
$mobile=$_POST['User']['mobile'];
$society = new \app\models\Society();
$random_number=mt_rand(10000, 99999);
$vp_string = trim($_POST['Society']['society_name']);

$vp_string = html_entity_decode($vp_string);

$vp_string = strip_tags($vp_string);

$vp_string = strtolower($vp_string);

$vp_string = preg_replace('[^ a-z0-9_\.]', ' ', $vp_string);

$vp_string = preg_replace('~ ~', '-', $vp_string);
$society->society_name = $_POST['Society']['society_name'];
$society->contact_person = $_POST['Society']['contact_person']; 
$society->address = $_POST['Society']['address'];       
$society->society_id =$random_number;
$society->mobile = $mobile;
$society->url = $vp_string;
$society->status =0;
$society->save();
$session = Yii::$app->session;
return $this->redirect(['regsuccess']);
}  
return $this->render('society', [
            'model' => $model,
            'society' => $society,

]);}