Answer the question
In order to leave comments, you need to log in
How to create entries in the database in Yii2 after registration?
How in YII2, after the user has registered, create 10 records in another table?
here is the user registration script
<?php
/**
* Created by PhpStorm.
* User: User
* Date: 23.04.2018
* Time: 19:31
*/
namespace app\models;
use Yii;
use yii\base\Model;
class Signup extends Model
{public $username;
public $email;
public $password;
public function rules()
{
return[
[['email','username','password'],'required'],
['email', 'email'],
['password','string','min'=>2,'max'=>30]
];
}
public function signup()
{
$developer=new Developers();
$developer->username=$this->username;
$developer->email=$this->email;
$developer->password=Yii::$app->getSecurity()->generatePasswordHash($this->password);
return $developer->save();
}
}
$model = new Product;
$model->category_id='2';
$model->author_id=$app->user->identity['id'];
$model->name='name';
$model->content='content';
$model->price='0';
$model->keywords='NULL';
$model->description='NULL';
$model->hit='0';
$model->new='0';
$model->save();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question