PHP Classes

File: crud/default/views/_form.php

Recommend this page to a friend!
  Classes of Insolita   Yii2 Giitwig   crud/default/views/_form.php   Download  
File: crud/default/views/_form.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Yii2 Giitwig
Implement CRUD applications using Twig templates
Author: By
Last change:
Date: 2 months ago
Size: 1,266 bytes
 

Contents

Class file image Download
<?php

use yii\helpers\Inflector;
use
yii\helpers\StringHelper;

/* @var $this yii\web\View */
/* @var $generator insolita\giitwig\crud\Generator */

/* @var $model \yii\db\ActiveRecord */
$model = new $generator->modelClass();
$safeAttributes = $model->safeAttributes();
if (empty(
$safeAttributes)) {
   
$safeAttributes = $model->attributes();
}

?>

{{ use('yii/widgets/ActiveForm') }}

<div class="<?= Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-form">
    {% set form = active_form_begin({
           'id' : '<?= Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-form',
           'options' : {'class' : 'form-horizontal'},
    }) %}

<?php foreach ($generator->getColumnNames() as $attribute) {
    if (
in_array($attribute, $safeAttributes)) {
        echo
"{{ " . $generator->generateActiveField($attribute) . "| raw }} \n\n";
    }
}
?>
<div class="form-group">
        {% if model.isNewRecord %}
           {{html.submitButton( <?= $generator->generateString('Create') ?>,{'class':'btn btn-success'})|raw}}
        {% else %}
           {{html.submitButton( <?= $generator->generateString('Update') ?>,{'class':'btn btn-primary'})|raw}}
        {% endif %}
    </div>

    {{ active_form_end() }}

</div>