-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate CRUD on Access.
- Loading branch information
Showing
10 changed files
with
484 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
|
||
namespace app\controllers; | ||
|
||
use Yii; | ||
use app\models\Access; | ||
use app\models\search\AccessSearch; | ||
use yii\web\Controller; | ||
use yii\web\NotFoundHttpException; | ||
use yii\filters\VerbFilter; | ||
|
||
/** | ||
* AccessController implements the CRUD actions for Access model. | ||
*/ | ||
class AccessController extends Controller | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function behaviors() | ||
{ | ||
return [ | ||
'verbs' => [ | ||
'class' => VerbFilter::className(), | ||
'actions' => [ | ||
'delete' => ['POST'], | ||
], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Lists all Access models. | ||
* @return mixed | ||
*/ | ||
public function actionIndex() | ||
{ | ||
$searchModel = new AccessSearch(); | ||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); | ||
|
||
return $this->render('index', [ | ||
'searchModel' => $searchModel, | ||
'dataProvider' => $dataProvider, | ||
]); | ||
} | ||
|
||
/** | ||
* Displays a single Access model. | ||
* @param integer $id | ||
* @return mixed | ||
*/ | ||
public function actionView($id) | ||
{ | ||
return $this->render('view', [ | ||
'model' => $this->findModel($id), | ||
]); | ||
} | ||
|
||
/** | ||
* Creates a new Access model. | ||
* If creation is successful, the browser will be redirected to the 'view' page. | ||
* @return mixed | ||
*/ | ||
public function actionCreate() | ||
{ | ||
$model = new Access(); | ||
|
||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||
return $this->redirect(['view', 'id' => $model->id]); | ||
} else { | ||
return $this->render('create', [ | ||
'model' => $model, | ||
]); | ||
} | ||
} | ||
|
||
/** | ||
* Updates an existing Access model. | ||
* If update is successful, the browser will be redirected to the 'view' page. | ||
* @param integer $id | ||
* @return mixed | ||
*/ | ||
public function actionUpdate($id) | ||
{ | ||
$model = $this->findModel($id); | ||
|
||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||
return $this->redirect(['view', 'id' => $model->id]); | ||
} else { | ||
return $this->render('update', [ | ||
'model' => $model, | ||
]); | ||
} | ||
} | ||
|
||
/** | ||
* Deletes an existing Access model. | ||
* If deletion is successful, the browser will be redirected to the 'index' page. | ||
* @param integer $id | ||
* @return mixed | ||
*/ | ||
public function actionDelete($id) | ||
{ | ||
$this->findModel($id)->delete(); | ||
|
||
return $this->redirect(['index']); | ||
} | ||
|
||
/** | ||
* Finds the Access model based on its primary key value. | ||
* If the model is not found, a 404 HTTP exception will be thrown. | ||
* @param integer $id | ||
* @return Access the loaded model | ||
* @throws NotFoundHttpException if the model cannot be found | ||
*/ | ||
protected function findModel($id) | ||
{ | ||
if (($model = Access::findOne($id)) !== null) { | ||
return $model; | ||
} else { | ||
throw new NotFoundHttpException('The requested page does not exist.'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace app\models; | ||
|
||
use Yii; | ||
|
||
/** | ||
* This is the model class for table "access". | ||
* | ||
* @property integer $id | ||
* @property integer $userOwner | ||
* @property integer $userGuest | ||
* @property string $date | ||
* | ||
* @property Users $userGuest0 | ||
* @property Users $userOwner0 | ||
*/ | ||
class Access extends \yii\db\ActiveRecord | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public static function tableName() | ||
{ | ||
return 'access'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
[['userOwner', 'userGuest', 'date'], 'required'], | ||
[['userOwner', 'userGuest'], 'integer'], | ||
[['date'], 'safe'], | ||
[['userGuest'], 'exist', 'skipOnError' => true, 'targetClass' => Users::className(), 'targetAttribute' => ['userGuest' => 'id']], | ||
[['userOwner'], 'exist', 'skipOnError' => true, 'targetClass' => Users::className(), 'targetAttribute' => ['userOwner' => 'id']], | ||
]; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function attributeLabels() | ||
{ | ||
return [ | ||
'id' => Yii::t('app', 'ID'), | ||
'userOwner' => Yii::t('app', 'User Owner'), | ||
'userGuest' => Yii::t('app', 'User Guest'), | ||
'date' => Yii::t('app', 'Date'), | ||
]; | ||
} | ||
|
||
/** | ||
* @return \yii\db\ActiveQuery | ||
*/ | ||
public function getUserGuest0() | ||
{ | ||
return $this->hasOne(Users::className(), ['id' => 'userGuest']); | ||
} | ||
|
||
/** | ||
* @return \yii\db\ActiveQuery | ||
*/ | ||
public function getUserOwner0() | ||
{ | ||
return $this->hasOne(Users::className(), ['id' => 'userOwner']); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* @return \app\models\query\AccessQuery the active query used by this AR class. | ||
*/ | ||
public static function find() | ||
{ | ||
return new \app\models\query\AccessQuery(get_called_class()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace app\models\query; | ||
|
||
/** | ||
* This is the ActiveQuery class for [[\app\models\Access]]. | ||
* | ||
* @see \app\models\Access | ||
*/ | ||
class AccessQuery extends \yii\db\ActiveQuery | ||
{ | ||
/*public function active() | ||
{ | ||
return $this->andWhere('[[status]]=1'); | ||
}*/ | ||
|
||
/** | ||
* @inheritdoc | ||
* @return \app\models\Access[]|array | ||
*/ | ||
public function all($db = null) | ||
{ | ||
return parent::all($db); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* @return \app\models\Access|array|null | ||
*/ | ||
public function one($db = null) | ||
{ | ||
return parent::one($db); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace app\models\search; | ||
|
||
use Yii; | ||
use yii\base\Model; | ||
use yii\data\ActiveDataProvider; | ||
use app\models\Access; | ||
|
||
/** | ||
* AccessSearch represents the model behind the search form about `app\models\Access`. | ||
*/ | ||
class AccessSearch extends Access | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
[['id', 'userOwner', 'userGuest'], 'integer'], | ||
[['date'], '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 = Access::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, | ||
'userOwner' => $this->userOwner, | ||
'userGuest' => $this->userGuest, | ||
'date' => $this->date, | ||
]); | ||
|
||
return $dataProvider; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
use yii\helpers\Html; | ||
use yii\widgets\ActiveForm; | ||
|
||
/* @var $this yii\web\View */ | ||
/* @var $model app\models\Access */ | ||
/* @var $form yii\widgets\ActiveForm */ | ||
?> | ||
|
||
<div class="access-form"> | ||
|
||
<?php $form = ActiveForm::begin(); ?> | ||
|
||
<?= $form->field($model, 'userOwner')->textInput() ?> | ||
|
||
<?= $form->field($model, 'userGuest')->textInput() ?> | ||
|
||
<?= $form->field($model, 'date')->textInput() ?> | ||
|
||
<div class="form-group"> | ||
<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | ||
</div> | ||
|
||
<?php ActiveForm::end(); ?> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
use yii\helpers\Html; | ||
use yii\widgets\ActiveForm; | ||
|
||
/* @var $this yii\web\View */ | ||
/* @var $model app\models\search\AccessSearch */ | ||
/* @var $form yii\widgets\ActiveForm */ | ||
?> | ||
|
||
<div class="access-search"> | ||
|
||
<?php $form = ActiveForm::begin([ | ||
'action' => ['index'], | ||
'method' => 'get', | ||
]); ?> | ||
|
||
<?= $form->field($model, 'id') ?> | ||
|
||
<?= $form->field($model, 'userOwner') ?> | ||
|
||
<?= $form->field($model, 'userGuest') ?> | ||
|
||
<?= $form->field($model, 'date') ?> | ||
|
||
<div class="form-group"> | ||
<?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?> | ||
<?= Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?> | ||
</div> | ||
|
||
<?php ActiveForm::end(); ?> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
use yii\helpers\Html; | ||
|
||
|
||
/* @var $this yii\web\View */ | ||
/* @var $model app\models\Access */ | ||
|
||
$this->title = Yii::t('app', 'Create Access'); | ||
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Accesses'), 'url' => ['index']]; | ||
$this->params['breadcrumbs'][] = $this->title; | ||
?> | ||
<div class="access-create"> | ||
|
||
<h1><?= Html::encode($this->title) ?></h1> | ||
|
||
<?= $this->render('_form', [ | ||
'model' => $model, | ||
]) ?> | ||
|
||
</div> |
Oops, something went wrong.