Skip to content

Commit

Permalink
className() is deprecated since 2.0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
eluhr committed Mar 24, 2023
1 parent 47bf621 commit 51972d6
Show file tree
Hide file tree
Showing 24 changed files with 96 additions and 94 deletions.
6 changes: 3 additions & 3 deletions src/generators/crud/callbacks/devgroup/Jsoneditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class Jsoneditor
public static function field()
{
return function ($attribute) {
$collapse = Collapse::className();
$editor = \devgroup\jsoneditor\Jsoneditor::className();
$collapse = Collapse::class;
$editor = \devgroup\jsoneditor\Jsoneditor::class;

return <<<FORMAT
'<div class="field-widget-{$attribute}">'.
Expand All @@ -39,7 +39,7 @@ public static function field()
public static function attribute()
{
return function ($attribute, $generator) {
$formattter = StringFormatter::className();
$formattter = StringFormatter::class;
$method = __METHOD__;

return <<<FORMAT
Expand Down
6 changes: 3 additions & 3 deletions src/generators/crud/callbacks/dmstr/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class Pages
public static function dropdown()
{
return function () {
$input = TreeViewInput::className();
$tree = Tree::className();
$input = TreeViewInput::class;
$tree = Tree::class;

return <<<CODE
\$form->field(\$model, 'request_param')->widget(
{$input}::className(),
{$input}::class,
[
// single query fetch to render the tree
'query' => {$tree}::find()->addOrderBy('root, lft'),
Expand Down
2 changes: 1 addition & 1 deletion src/generators/crud/default/controller-rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function behaviors()
parent::behaviors(),
[
'access' => [
'class' => AccessControl::className(),
'class' => AccessControl::class,
'rules' => [
[
'allow' => true,
Expand Down
2 changes: 1 addition & 1 deletion src/generators/crud/default/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'class' => AccessControl::class,
'rules' => [
<?php
foreach($accessDefinitions['roles'] as $roleName => $actions){
Expand Down
2 changes: 1 addition & 1 deletion src/generators/crud/default/views/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<?php echo '<?php $this->endBlock(); ?>'; ?>

<?php
$label = substr(strrchr($model::className(), '\\'), 1);
$label = substr(strrchr($model::class, '\\'), 1);

$items = <<<EOS
[
Expand Down
4 changes: 2 additions & 2 deletions src/generators/crud/default/views/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
use yii\helpers\Inflector;
use yii\helpers\StringHelper;

/*
/**
* @var yii\web\View $this
* @var yii\gii\generators\crud\Generator $generator
*/

/** @var \yii\db\ActiveRecord $model */
$model = new $generator->modelClass();
$model->setScenario('crud');
$modelName = Inflector::camel2words(StringHelper::basename($model::className()));
$modelName = Inflector::camel2words(StringHelper::basename($model::class));


echo "<?php\n";
Expand Down
4 changes: 2 additions & 2 deletions src/generators/crud/default/views/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
$model->setScenario('crud');
}

$baseName = StringHelper::basename($model::className());
$baseName = StringHelper::basename($model::class);
$modelName = Inflector::camel2words($baseName);

$safeAttributes = $model->safeAttributes();
Expand Down Expand Up @@ -190,7 +190,7 @@
<?= '<?= ' ?>GridView::widget([
'dataProvider' => $dataProvider,
'pager' => [
'class' => yii\widgets\LinkPager::className(),
'class' => yii\widgets\LinkPager::class,
'firstPageLabel' => <?= $generator->generateString('First') ?>,
'lastPageLabel' => <?= $generator->generateString('Last').",\n" ?>
],
Expand Down
6 changes: 3 additions & 3 deletions src/generators/crud/default/views/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
use yii\helpers\Inflector;
use yii\helpers\StringHelper;

/*
/**
* @var yii\web\View $this
* @var yii\gii\generators\crud\Generator $generator
*/

$urlParams = $generator->generateUrlParams();
$model = new $generator->modelClass();
$model->setScenario('crud');
$className = $model::className();
$modelName = Inflector::camel2words(StringHelper::basename($model::className()));
$className = $model::class;
$modelName = Inflector::camel2words(StringHelper::basename($model::class));

echo "<?php\n";
?>
Expand Down
2 changes: 1 addition & 1 deletion src/generators/crud/default/views/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
$safeAttributes = $model::getTableSchema()->columnNames;
}

$className = $model::className();
$className = $model::class;
$modelName = Inflector::camel2words(StringHelper::basename($className));
$urlParams = $generator->generateUrlParams();

Expand Down
2 changes: 1 addition & 1 deletion src/generators/crud/editable/controller-rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function behaviors()
parent::behaviors(),
[
'access' => [
'class' => AccessControl::className(),
'class' => AccessControl::class,
'rules' => [
[
'allow' => true,
Expand Down
60 changes: 30 additions & 30 deletions src/generators/crud/editable/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'class' => AccessControl::class,
'rules' => [
<?php
<?php
foreach($accessDefinitions['roles'] as $roleName => $actions){
?>
[
Expand All @@ -74,7 +74,7 @@ public function behaviors()
],
'roles' => ['<?=$roleName?>'],
],
<?php
<?php
}
?> ],
],
Expand All @@ -85,12 +85,12 @@ public function behaviors()
public function actions() {
return [
'editable-column-update' => [
'class' => EditableColumnAction::className(), // action class name
'modelClass' => <?=$modelClass?>::className(),
'class' => EditableColumnAction::class, // action class name
'modelClass' => <?=$modelClass?>::class,
],
];
}
}

/**
* Lists all <?= $modelClass ?> models.
* @return mixed
Expand All @@ -101,13 +101,13 @@ public function actionIndex()
?>
$searchModel = new <?= $searchModelClassName ?>;
$dataProvider = $searchModel->search($_GET);
<?php
<?php
} else {
?>
$dataProvider = new ActiveDataProvider([
'query' => <?= $modelClass ?>::find(),
]);
<?php
<?php
} ?>

Url::remember();
Expand Down Expand Up @@ -139,7 +139,7 @@ public function actionView(<?= $actionParams ?>)

/**
* Creates a new <?= $modelClass ?> model.
* If creation is successful, the browser will be redirected
* If creation is successful, the browser will be redirected
* to the 'view' page or back, if parameter $goBack is true.
* @return mixed
*/
Expand All @@ -148,12 +148,12 @@ public function actionCreate()
$model = new <?= $modelClass ?>;
$model->load($_GET);
$relAttributes = $model->attributes;

try {
if ($model->load($_POST) && $model->save()) {
if($relAttributes){
return $this->goBack();
}
}
return $this->redirect(['view', <?= $urlParams ?>]);
} elseif (!\Yii::$app->request->isPost) {
$model->load($_GET);
Expand All @@ -162,13 +162,13 @@ public function actionCreate()
$msg = (isset($e->errorInfo[2]))?$e->errorInfo[2]:$e->getMessage();
$model->addError('_exception', $msg);
}

return $this->render('create', [
'model' => $model,
'relAttributes' => $relAttributes,
'relAttributes' => $relAttributes,
]);
}

/**
* Add a new TestContacts record for relation grid and redirect back.
* @return mixed
Expand All @@ -181,7 +181,7 @@ public function actionCreateForRel()
$model->save();
return $this->goBack();
}

/**
* Updates an existing <?= $modelClass ?> model.
* If update is successful, the browser will be redirected to the 'view' page.
Expand All @@ -193,15 +193,15 @@ public function actionUpdate(<?= $actionParams ?>)
$model = new <?= $modelClass ?>;
$model->load($_GET);
$relAttributes = $model->attributes;

$model = $this->findModel(<?= $actionParams ?>);

if ($model->load($_POST) && $model->save()) {
return $this->redirect(Url::previous());
} else {
return $this->render('update', [
'model' => $model,
'relAttributes' => $relAttributes
'relAttributes' => $relAttributes
]);
}
}
Expand All @@ -224,11 +224,11 @@ public function actionDelete(<?= $actionParams ?>)

$model = new <?= $modelClass ?>;
$model->load($_GET);
$relAttributes = $model->attributes;
$relAttributes = $model->attributes;
if($relAttributes){
return $this->redirect(Url::previous());
}
}

// TODO: improve detection
$isPivot = strstr('<?= $actionParams ?>',',');
if ($isPivot == true) {
Expand All @@ -248,23 +248,23 @@ public function actionDelete(<?= $actionParams ?>)
* Update <?= $modelClass ?> model record by editable.
* <?= implode("\n\t * ", $actionParamComments)."\n" ?>
* @return mixed
*/
*/
public function actionEditable(<?= $actionParams ?>){

// Check if there is an Editable ajax request
if (!isset($_POST['hasEditable'])) {
return false;
}

$post = [];
foreach($_POST as $name => $value){
//if(in_array($name,$this->editAbleFileds)){
$post[$name] = $value;
//}
}

// use Yii's response format to encode output as JSON
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
if(!$post){
return ['output'=>'', 'message'=> <?=$generator->generateString('Can not update this field') ?>];
}
Expand All @@ -288,16 +288,16 @@ public function actionEditable(<?= $actionParams ?>){
$errors = [];
foreach($model->errors as $field => $messages){
foreach($messages as $message){
$errors[] = $model->getAttributeLabel($field)
$errors[] = $model->getAttributeLabel($field)
. ': '
. $message;
}
}
return ['output'=>'', 'message'=>implode('<br>',$errors)];

}
}

}

/**
* Finds the <?= $modelClass ?> model based on its primary key value.
Expand Down
6 changes: 3 additions & 3 deletions src/generators/crud/editable/views/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @var yii\web\View $this
* @var <?= ltrim($generator->modelClass, '\\') ?> $model
* @var yii\widgets\ActiveForm $form
* @var string $relAttributes relation fields names for disabling
* @var string $relAttributes relation fields names for disabling
*/

?>
Expand Down Expand Up @@ -79,11 +79,11 @@
<?php echo '<?php $this->endBlock(); ?>'; ?>

<?php
$label = substr(strrchr($model::className(), '\\'), 1);
$label = substr(strrchr($model::class, '\\'), 1);

$items = <<<EOS
[
'label' => Yii::t('$generator->messageCategory', StringHelper::basename('{$model::className()}')),
'label' => Yii::t('$generator->messageCategory', StringHelper::basename('{$model::class}')),
'content' => \$this->blocks['main'],
'active' => true,
],
Expand Down
6 changes: 3 additions & 3 deletions src/generators/crud/editable/views/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
use yii\helpers\Inflector;
use yii\helpers\StringHelper;

/*
/**
* @var yii\web\View $this
* @var yii\gii\generators\crud\Generator $generator
*/

/** @var \yii\db\ActiveRecord $model */
$model = new $generator->modelClass();
$model->setScenario('crud');
$modelName = StringHelper::basename($model::className());
$modelName = StringHelper::basename($model::class);


echo "<?php\n";
Expand All @@ -29,7 +29,7 @@
}

$this->title = <?= $generator->generateString('Create') ?>;
$this->params['breadcrumbs'][] = ['label' => Yii::t('<?= $generator->messageCategory ?>', '<?=Inflector::pluralize(StringHelper::basename($model::className())) ?>'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => Yii::t('<?= $generator->messageCategory ?>', '<?=Inflector::pluralize(StringHelper::basename($model::class)) ?>'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="giiant-crud <?= Inflector::camel2id(StringHelper::basename($generator->modelClass), '-', true) ?>-create">
Expand Down
Loading

0 comments on commit 51972d6

Please sign in to comment.