Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features #300

Merged
merged 50 commits into from
Mar 26, 2024
Merged
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
258bab4
Made generate relation from current schema an configurable option
eluhr Sep 7, 2021
acbe3b7
fixed model relation 1:n (pick one) n:m (pick many)
eluhr Sep 7, 2021
f846803
disable pluralization
eluhr Sep 20, 2021
780075d
updated name generation for relations
eluhr Oct 8, 2021
e98dc79
Disable pluralization via property and append an "N" instead for n:m
eluhr Oct 8, 2021
a4caba4
updated model and crud generation
eluhr Oct 11, 2021
a3d439c
updated model and query template
eluhr Oct 12, 2021
77457e8
updated relation name and fixed view.php template
eluhr Oct 13, 2021
10381a9
Fixed relation provider
eluhr Oct 20, 2021
d57f308
Added translatables in view and index
eluhr Nov 4, 2021
c3d7fd8
translatable for detail tab label
eluhr Dec 9, 2021
667f8e2
updated controller
eluhr Dec 14, 2021
d2a659f
Grid max columns
eluhr Jan 20, 2022
1def178
Merge commit '1dbc6ede1e69d0a1d5064f8826fa2f2961d93b23' into feature/…
eluhr Jan 24, 2022
0e3376a
introduce different optional scenarios
eluhr Jan 24, 2022
813ccb4
removed not needed code
eluhr Feb 1, 2022
b4a80b9
another scenario for detail relation
eluhr Feb 22, 2022
6a2bc96
bug fix for not defined relations
eluhr Feb 22, 2022
f2352c7
merge with parent method calls
eluhr Mar 23, 2023
6c539d7
Merge branch 'master' into dev/elias
eluhr Mar 24, 2023
890f9e9
Merge commit 'f2352c7b39d14f36de493d5c780d2b232229ddd7' into dev/elias
eluhr Mar 24, 2023
40c195b
catch throwable because a component can be wrong implemented
eluhr Mar 24, 2023
08bd2a5
cleanup controller
eluhr Mar 24, 2023
47bf621
added comment for model extended
eluhr Mar 24, 2023
51972d6
className() is deprecated since 2.0.14
eluhr Mar 24, 2023
059de44
adapt changes from other experiences
eluhr Mar 24, 2023
9cdfdeb
render searchfile only when needed
eluhr Mar 24, 2023
e5579bc
call static method
eluhr Mar 24, 2023
9dd40b6
no meta search
eluhr Mar 25, 2023
b5dd8ee
generate translation trait if needed
eluhr Mar 27, 2023
4cd779f
fixed relation column name
eluhr Mar 27, 2023
f33a31c
simplify form view(s)
eluhr Mar 27, 2023
86aeff6
Fix controller syntax and structure + remove deprecations and not nee…
eluhr Jan 4, 2024
ea3447b
Merge commit 'f33a31c10cbb709d06c4c407e877288e179fbe63' into feature/…
eluhr Jan 4, 2024
a20f236
small cleanups
eluhr Jan 4, 2024
16dae88
php 8 deprecation string in trim fix
eluhr Jan 4, 2024
633c6e9
use getters
eluhr Jan 4, 2024
56cb77f
remove overhead
eluhr Jan 4, 2024
8850223
use datetime imutable instead of db expression
eluhr Jan 4, 2024
3eff8bd
unique validator with targetClass so in works for translations
eluhr Jan 4, 2024
c69b994
break out of loop to prevent overloading
eluhr Jan 29, 2024
3b4b63a
Fixed access definitions
eluhr Jan 29, 2024
5d9faae
remove go back to avoid void targets -> redirect to home screen
eluhr Jan 30, 2024
98f4794
Allow clear for relations which are nullable
eluhr Jan 31, 2024
c8a1f1e
allow list crud
eluhr Feb 6, 2024
2e2eb45
to remove potential out of memory error
eluhr Feb 12, 2024
53c7802
fix label in forms
eluhr Mar 25, 2024
db9af44
introduce enable or disable copy function
eluhr Mar 26, 2024
d1f3358
Merge branch 'master' into feature/dev-elias
schmunk42 Mar 26, 2024
38b96a8
added artifacts
schmunk42 Mar 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleanup controller
  • Loading branch information
eluhr committed Mar 24, 2023
commit 08bd2a50ccc34e4c1d4b33b8943de8eae72769f8
44 changes: 16 additions & 28 deletions src/generators/crud/default/controller.php
Original file line number Diff line number Diff line change
@@ -48,7 +48,6 @@
<?php if($generator->accessFilter): ?>
use yii\filters\AccessControl;
<?php endif; ?>
use dmstr\bootstrap\Tabs;
use Yii;
use yii\web\NotFoundHttpException;

@@ -65,12 +64,6 @@ class <?= $controllerClass ?> extends <?= StringHelper::basename($generator->bas
}
?>

/**
* @var boolean whether to enable CSRF validation for the actions in this controller.
* CSRF validation is enabled only when both this property and [[Request::enableCsrfValidation]] are true.
*/
public $enableCsrfValidation = false;

<?php if ($generator->accessFilter): ?>
/**
* @inheritdoc
@@ -81,17 +74,17 @@ public function behaviors()
'access' => [
'class' => AccessControl::className(),
'rules' => [
<?php
<?php
foreach($accessDefinitions['roles'] as $roleName => $actions){
?>
[
'allow' => true,
'actions' => ['<?=implode("', '",$actions)?>'],
'roles' => ['<?=$roleName?>'],
],
<?php
<?php
}
?>
?>
],
],
];
@@ -101,28 +94,24 @@ public function behaviors()
/**
* Lists all <?= $modelClass ?> models.
*
* @throws yii\base\InvalidConfigException
* @return string
*/
public function actionIndex()
{
<?php if ($searchModelClass !== '') {
?>
$searchModel = new <?= $searchModelClassName ?>();
$dataProvider = $searchModel->search($_GET);
$searchModel = Yii::createObject(<?php echo $searchModelClassName ?>::class);
$dataProvider = $searchModel->search($this->request->get());
<?php
} else {
?>
$dataProvider = new \yii\data\ActiveDataProvider([
$dataProvider = new ActiveDataProvider([
'query' => <?= $modelClass ?>::find(),
]);
<?php
} ?>

Tabs::clearLocalStorage();

Url::remember();
Yii::$app->session->set('__crudReturnUrl', null);

return $this->render('index', [
'dataProvider' => $dataProvider,
<?php if ($searchModelClass !== ''): ?>
@@ -141,27 +130,25 @@ public function actionIndex()
*/
public function actionView(<?= $actionParams ?>)
{
Yii::$app->session->set('__crudReturnUrl', Url::previous());
Url::remember();
Tabs::rememberActiveState();
return $this->render('view', ['model' => $this->findModel(<?= $actionParams ?>)]);
}

/**
* Creates a new <?= $modelClass ?> model.
* If creation is successful, the browser will be redirected to the 'view' page.
*
* @throws yii\base\InvalidConfigException
* @return string|\yii\web\Response
*/
public function actionCreate()
{
$model = new <?= $modelClass ?>();
$model = Yii::createObject(<?php echo $modelClass ?>::class);
try {
if ($model->load(Yii::$app->request->post()) && $model->save()) {
if ($model->load($this->request->post()) && $model->save()) {
return $this->redirect(['view', <?= $urlParams ?>]);
}
if (!Yii::$app->request->isPost) {
$model->load(Yii::$app->request->get());
$model->load($this->request->get());
}
} catch (\Exception $e) {
$model->addError('_exception', $e->errorInfo[2] ?? $e->getMessage());
@@ -174,13 +161,14 @@ public function actionCreate()
* If update is successful, the browser will be redirected to the 'view' page.
*
* <?= implode("\n\t * ", $actionParamComments)."\n" ?>
* @return string|\yii\web\Response
*
* @throws \yii\web\HttpException
* @return string|\yii\web\Response
*/
public function actionUpdate(<?= $actionParams ?>)
{
$model = $this->findModel(<?= $actionParams ?>);
if ($model->load($_POST) && $model->save()) {
if ($model->load($this->request->post()) && $model->save()) {
return $this->redirect(Url::previous());
}
return $this->render('update', ['model' => $model]);
@@ -200,7 +188,6 @@ public function actionDelete(<?= $actionParams ?>)
$this->findModel(<?= $actionParams ?>)->delete();
} catch (\Exception $e) {
Yii::$app->getSession()->addFlash('error', $e->errorInfo[2] ?? $e->getMessage());
return $this->redirect(Url::previous());
}

return $this->redirect(['index']);
@@ -211,8 +198,9 @@ public function actionDelete(<?= $actionParams ?>)
* If the model is not found, a 404 HTTP exception will be thrown.
*
* <?= implode("\n\t * ", $actionParamComments)."\n" ?>
* @return <?= $modelClass ?> the loaded model
*
* @throws NotFoundHttpException if the model cannot be found
* @return <?= $modelClass ?> the loaded model
*/
protected function findModel(<?= $actionParams ?>)
{