This commit is contained in:
Chenx221 2024-02-09 12:15:09 +08:00
parent c083f404c2
commit cde47b6261
26 changed files with 1070 additions and 73 deletions

View File

@ -14,10 +14,13 @@
},
"minimum-stability": "stable",
"require": {
"php": ">=7.4.0",
"php": ">=8.2.0",
"yiisoft/yii2": "~2.0.45",
"yiisoft/yii2-bootstrap5": "~2.0.2",
"yiisoft/yii2-symfonymailer": "~2.0.3"
"yiisoft/yii2-symfonymailer": "~2.0.3",
"sam-it/yii2-mariadb": "^3.1",
"bestyii/yii2-gii-rest": "*",
"bestyii/yii2-openapi-reader": "dev-master"
},
"require-dev": {
"yiisoft/yii2-debug": "~2.1.0",

View File

@ -1,11 +1,16 @@
<?php
use yii\db\Connection;
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii2basic',
'class' => Connection::class,
'dsn' => 'mysql:host=localhost:3307;dbname=yii2basic',
'username' => 'root',
'password' => '',
'password' => 'chenx221',
'charset' => 'utf8',
'schemaMap' => [
'mysql' => SamIT\Yii2\MariaDb\Schema::class
]
// Schema cache options (for production environment)
//'enableSchemaCache' => true,

View File

@ -9,12 +9,12 @@ $config = [
'bootstrap' => ['log'],
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
'@npm' => '@vendor/npm-asset',
],
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '',
'cookieValidationKey' => '9vuTNyfQqTOWY8fhAajrAhOfX_uaZqZZ',
],
'cache' => [
'class' => 'yii\caching\FileCache',
@ -67,7 +67,15 @@ if (YII_ENV_DEV) {
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
'allowedIPs' => ['127.0.0.1', '::1', '192.168.1.*'],
'generators' => [ //自定义生成器
'rest-model' => [ // generator name
'class' => 'bestyii\giiRest\generators\model\Generator', // generator class
],
'rest-crud' => [ // generator name
'class' => 'bestyii\giiRest\generators\crud\Generator', // generator class
]
],
];
}

View File

@ -0,0 +1,134 @@
<?php
namespace app\controllers;
use app\models\Country;
use app\models\CountrySearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* CountryController implements the CRUD actions for Country model.
*/
class CountryController extends Controller
{
/**
* @inheritDoc
*/
public function behaviors()
{
return array_merge(
parent::behaviors(),
[
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
]
);
}
/**
* Lists all Country models.
*
* @return string
*/
public function actionIndex()
{
$searchModel = new CountrySearch();
$dataProvider = $searchModel->search($this->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Country model.
* @param string $code Code
* @return string
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($code)
{
return $this->render('view', [
'model' => $this->findModel($code),
]);
}
/**
* Creates a new Country model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return string|\yii\web\Response
*/
public function actionCreate()
{
$model = new Country();
if ($this->request->isPost) {
if ($model->load($this->request->post()) && $model->save()) {
return $this->redirect(['view', 'code' => $model->code]);
}
} else {
$model->loadDefaultValues();
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing Country model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param string $code Code
* @return string|\yii\web\Response
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($code)
{
$model = $this->findModel($code);
if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
return $this->redirect(['view', 'code' => $model->code]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing Country model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param string $code Code
* @return \yii\web\Response
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($code)
{
$this->findModel($code)->delete();
return $this->redirect(['index']);
}
/**
* Finds the Country model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param string $code Code
* @return Country the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($code)
{
if (($model = Country::findOne(['code' => $code])) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}

View File

@ -2,6 +2,7 @@
namespace app\controllers;
use app\models\EntryForm;
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
@ -125,4 +126,24 @@ class SiteController extends Controller
{
return $this->render('about');
}
/**
* Displays hello page.
*
* @return string
*/
public function actionSay($message = 'hello')
{
return $this->render('say', ['message' => $message]);
}
public function actionEntry()
{
$model = new EntryForm();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
return $this->render('entry-confirm', ['model' => $model]);
} else {
return $this->render('entry', ['model' => $model]);
}
}
}

View File

@ -0,0 +1,195 @@
<?php
namespace app\controllers;
use app\models\User;
use app\models\UserSearch;
use Yii;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* UserController implements the CRUD actions for User model.
*/
class UserController extends Controller
{
/**
* @inheritDoc
*/
public function behaviors()
{
return array_merge(
parent::behaviors(),
[
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
]
);
}
/**
* Lists all User models.
*
* @return string
*/
public function actionIndex()
{
$searchModel = new UserSearch();
$dataProvider = $searchModel->search($this->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single User model.
* @param int $id ID
* @return string
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new User model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return string|\yii\web\Response
*/
public function actionCreate()
{
$model = new User();
if ($this->request->isPost) {
if ($model->load($this->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
} else {
$model->loadDefaultValues();
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing User model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param int $id ID
* @return string|\yii\web\Response
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing User model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param int $id ID
* @return \yii\web\Response
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the User model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param int $id ID
* @return User the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = User::findOne(['id' => $id])) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
/**
* Displays the login page.
* @return string|\yii\web\Response
*/
public function actionLogin()
{
if (!Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new User();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if ($model->login()) {
return $this->goBack();
} else {
Yii::$app->session->setFlash('error', 'Invalid username or password.');
}
}
return $this->render('login', [
'model' => $model,
]);
}
/**
* Logs out the current user.
* @return \yii\web\Response
*/
public function actionLogout()
{
Yii::$app->user->logout();
return $this->goHome();
}
/**
* Displays the registration page.
* @return string|\yii\web\Response
*/
public function actionRegister()
{
$model = new User();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$model->password = Yii::$app->security->generatePasswordHash($model->password);
$model->auth_key = Yii::$app->security->generateRandomString();
if ($model->save()) {
Yii::$app->session->setFlash('success', 'Registration successful. You can now log in.');
return $this->redirect(['login']);
} else {
Yii::$app->session->setFlash('error', 'Failed to register user.');
}
}
return $this->render('register', [
'model' => $model,
]);
}
}

49
models/Country.php Normal file
View File

@ -0,0 +1,49 @@
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "country".
*
* @property string $code
* @property string $name
* @property int $population
*/
class Country extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'country';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['code', 'name'], 'required'],
[['population'], 'integer'],
[['code'], 'string', 'max' => 2],
[['name'], 'string', 'max' => 52],
[['code'], 'unique'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'code' => 'Code',
'name' => 'Name',
'population' => 'Population',
];
}
}

69
models/CountrySearch.php Normal file
View File

@ -0,0 +1,69 @@
<?php
namespace app\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Country;
/**
* CountrySearch represents the model behind the search form of `app\models\Country`.
*/
class CountrySearch extends Country
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['code', 'name'], 'safe'],
[['population'], 'integer'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Country::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'population' => $this->population,
]);
$query->andFilterWhere(['like', 'code', $this->code])
->andFilterWhere(['like', 'name', $this->name]);
return $dataProvider;
}
}

18
models/EntryForm.php Normal file
View File

@ -0,0 +1,18 @@
<?php
namespace app\models;
use Yii;
use yii\base\Model;
class EntryForm extends Model
{
public $name;
public $email;
public function rules()
{
return [
[['name', 'email'], 'required'], // both name and email are required
['email', 'email'], // email has to be a valid email address
];
}
}

View File

@ -2,73 +2,85 @@
namespace app\models;
class User extends \yii\base\BaseObject implements \yii\web\IdentityInterface
use Yii;
use yii\web\IdentityInterface;
/**
* This is the model class for table "user".
*
* @property int $id 用户ID
* @property string|null $username 用户名
* @property string|null $password 密码
* @property string|null $auth_key authkey
* @property string|null $email 邮箱
* @property int|null $status 用户状态
*/
class User extends \yii\db\ActiveRecord implements IdentityInterface
{
public $id;
public $username;
public $password;
public $authKey;
public $accessToken;
private static $users = [
'100' => [
'id' => '100',
'username' => 'admin',
'password' => 'admin',
'authKey' => 'test100key',
'accessToken' => '100-token',
],
'101' => [
'id' => '101',
'username' => 'demo',
'password' => 'demo',
'authKey' => 'test101key',
'accessToken' => '101-token',
],
];
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'user';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['username', 'password'], 'required', 'on' => 'login'],
[['username', 'password', 'email'], 'required', 'on' => 'register'],
[['username', 'password', 'auth_key', 'email'], 'string', 'max' => 255],
[['status'], 'integer'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'username' => 'Username',
'password' => 'Password',
'auth_key' => 'Auth Key',
'email' => 'Email',
'status' => 'Status',
];
}
/**
* Finds an identity by the given ID.
*
* @param string|int $id the ID to be looked for
* @return IdentityInterface|null the identity object that matches the given ID.
*/
public static function findIdentity($id)
{
return isset(self::$users[$id]) ? new static(self::$users[$id]) : null;
return static::findOne($id);
}
/**
* {@inheritdoc}
* Finds an identity by the given token.
*
* @param mixed $token the token to be looked for
* @param mixed $type the type of the token. The value of this parameter depends on the implementation.
* For example, [[\yii\filters\auth\HttpBearerAuth]] will set this parameter to be `yii\filters\auth\HttpBearerAuth`.
* @return IdentityInterface|null the identity object that matches the given token.
*/
public static function findIdentityByAccessToken($token, $type = null)
{
foreach (self::$users as $user) {
if ($user['accessToken'] === $token) {
return new static($user);
}
}
// This method is not needed if you don't use access tokens for authentication.
return null;
}
/**
* Finds user by username
* Returns the ID of the user.
*
* @param string $username
* @return static|null
*/
public static function findByUsername($username)
{
foreach (self::$users as $user) {
if (strcasecmp($user['username'], $username) === 0) {
return new static($user);
}
}
return null;
}
/**
* {@inheritdoc}
* @return string|int the ID of the user
*/
public function getId()
{
@ -76,29 +88,23 @@ class User extends \yii\base\BaseObject implements \yii\web\IdentityInterface
}
/**
* {@inheritdoc}
* Returns an auth key used to authenticate cookie-based login.
*
* @return string the auth key
*/
public function getAuthKey()
{
return $this->authKey;
return $this->auth_key;
}
/**
* {@inheritdoc}
* Validates the given auth key.
*
* @param string $authKey the given auth key
* @return bool whether the given auth key is valid.
*/
public function validateAuthKey($authKey)
{
return $this->authKey === $authKey;
return $this->getAuthKey() === $authKey;
}
/**
* Validates password
*
* @param string $password password to validate
* @return bool if password provided is valid for current user
*/
public function validatePassword($password)
{
return $this->password === $password;
}
}
}

72
models/UserSearch.php Normal file
View File

@ -0,0 +1,72 @@
<?php
namespace app\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\User;
/**
* UserSearch represents the model behind the search form of `app\models\User`.
*/
class UserSearch extends User
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id', 'status'], 'integer'],
[['username', 'password', 'auth_key', 'email'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = User::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'status' => $this->status,
]);
$query->andFilterWhere(['like', 'username', $this->username])
->andFilterWhere(['like', 'password', $this->password])
->andFilterWhere(['like', 'auth_key', $this->auth_key])
->andFilterWhere(['like', 'email', $this->email]);
return $dataProvider;
}
}

27
views/country/_form.php Normal file
View File

@ -0,0 +1,27 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/** @var yii\web\View $this */
/** @var app\models\Country $model */
/** @var yii\widgets\ActiveForm $form */
?>
<div class="country-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'code')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'population')->textInput() ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

31
views/country/_search.php Normal file
View File

@ -0,0 +1,31 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/** @var yii\web\View $this */
/** @var app\models\CountrySearch $model */
/** @var yii\widgets\ActiveForm $form */
?>
<div class="country-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'code') ?>
<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'population') ?>
<div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-outline-secondary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

20
views/country/create.php Normal file
View File

@ -0,0 +1,20 @@
<?php
use yii\helpers\Html;
/** @var yii\web\View $this */
/** @var app\models\Country $model */
$this->title = 'Create Country';
$this->params['breadcrumbs'][] = ['label' => 'Countries', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="country-create">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

45
views/country/index.php Normal file
View File

@ -0,0 +1,45 @@
<?php
use app\models\Country;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\ActionColumn;
use yii\grid\GridView;
/** @var yii\web\View $this */
/** @var app\models\CountrySearch $searchModel */
/** @var yii\data\ActiveDataProvider $dataProvider */
$this->title = 'Countries';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="country-index">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Create Country', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'code',
'name',
'population',
[
'class' => ActionColumn::className(),
'urlCreator' => function ($action, Country $model, $key, $index, $column) {
return Url::toRoute([$action, 'code' => $model->code]);
}
],
],
]); ?>
</div>

21
views/country/update.php Normal file
View File

@ -0,0 +1,21 @@
<?php
use yii\helpers\Html;
/** @var yii\web\View $this */
/** @var app\models\Country $model */
$this->title = 'Update Country: ' . $model->name;
$this->params['breadcrumbs'][] = ['label' => 'Countries', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'code' => $model->code]];
$this->params['breadcrumbs'][] = 'Update';
?>
<div class="country-update">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

38
views/country/view.php Normal file
View File

@ -0,0 +1,38 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/** @var yii\web\View $this */
/** @var app\models\Country $model */
$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => 'Countries', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="country-view">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Update', ['update', 'code' => $model->code], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Delete', ['delete', 'code' => $model->code], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'code',
'name',
'population',
],
]) ?>
</div>

View File

@ -0,0 +1,12 @@
<?php
/** @var app\models\EntryForm $model */
use yii\helpers\Html;
?>
<p>你提交了以下信息</p>
<ul>
<li><label>Name:</label><?=
Html::encode($model->name) ?></li>
<li><label>Email:</label><?= Html::encode($model->email) ?></li>
</ul>

16
views/site/entry.php Normal file
View File

@ -0,0 +1,16 @@
<?php
/** @var app\models\EntryForm $model */
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'name')->label('Your Name') ?>
<?= $form->field($model, 'email')->label('Your Email') ?>
<div class="form-group">
<?= Html::submitButton('提交', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>

7
views/site/say.php Normal file
View File

@ -0,0 +1,7 @@
<?php
use yii\helpers\Html;
?>
<?=
/** @var string $message */
Html::encode($message)
?>

33
views/user/_form.php Normal file
View File

@ -0,0 +1,33 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/** @var yii\web\View $this */
/** @var app\models\User $model */
/** @var yii\widgets\ActiveForm $form */
?>
<div class="user-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'id')->textInput() ?>
<?= $form->field($model, 'username')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'password')->passwordInput(['maxlength' => true]) ?>
<?= $form->field($model, 'auth_key')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'email')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'status')->textInput() ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

37
views/user/_search.php Normal file
View File

@ -0,0 +1,37 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/** @var yii\web\View $this */
/** @var app\models\UserSearch $model */
/** @var yii\widgets\ActiveForm $form */
?>
<div class="user-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'username') ?>
<?= $form->field($model, 'password') ?>
<?= $form->field($model, 'auth_key') ?>
<?= $form->field($model, 'email') ?>
<?php // echo $form->field($model, 'status') ?>
<div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-outline-secondary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

20
views/user/create.php Normal file
View File

@ -0,0 +1,20 @@
<?php
use yii\helpers\Html;
/** @var yii\web\View $this */
/** @var app\models\User $model */
$this->title = 'Create User';
$this->params['breadcrumbs'][] = ['label' => 'Users', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-create">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

48
views/user/index.php Normal file
View File

@ -0,0 +1,48 @@
<?php
use app\models\User;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\ActionColumn;
use yii\grid\GridView;
/** @var yii\web\View $this */
/** @var app\models\UserSearch $searchModel */
/** @var yii\data\ActiveDataProvider $dataProvider */
$this->title = 'Users';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-index">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Create User', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'username',
'password',
'auth_key',
'email:email',
//'status',
[
'class' => ActionColumn::className(),
'urlCreator' => function ($action, User $model, $key, $index, $column) {
return Url::toRoute([$action, 'id' => $model->id]);
}
],
],
]); ?>
</div>

21
views/user/update.php Normal file
View File

@ -0,0 +1,21 @@
<?php
use yii\helpers\Html;
/** @var yii\web\View $this */
/** @var app\models\User $model */
$this->title = 'Update User: ' . $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Users', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Update';
?>
<div class="user-update">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

41
views/user/view.php Normal file
View File

@ -0,0 +1,41 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/** @var yii\web\View $this */
/** @var app\models\User $model */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Users', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="user-view">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Delete', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'username',
'password',
'auth_key',
'email:email',
'status',
],
]) ?>
</div>