/**
  * Returns a Variable model instance.
  * 
  * @param int $id
  * @return \yii\db\ActiveRecord
  * @throws NotFoundHttpException
  */
 protected function getModel($id = null)
 {
     $class = Variable::className();
     if ($id === null) {
         $m = new $class();
     } else {
         $m = $class::findOne($id);
         if ($m === null) {
             throw new NotFoundHttpException();
         }
     }
     return $m;
 }
 /**
  * Returns the table name of the variable model. You can override this 
  * method in order to provide a custom table name.
  * 
  * @return string
  */
 protected function getTableName()
 {
     return Variable::tableName();
 }
Exemplo n.º 3
0
 * @copyright   José Lorente
 * @version     1.0
 */
use jlorente\config\models\Variable;
use yii\widgets\ActiveForm;
use yii\helpers\Html;
/* @var $model jlorente\config\models\Variable */
/* @var $this yii\web\View */
$this->title = Yii::t('jlorente/config', 'Update Variable') . ' #' . $model->id;
?>
<div class="backend-container variable-model variable-update clearfix">
    <?php 
$form = ActiveForm::begin(['id' => 'config-variable-form']);
echo $form->field($model, 'code', ['inputOptions' => ['class' => 'form-control', 'disabled' => 'disabled']]);
echo $form->field($model, 'type')->dropDownList(Variable::getTypes(), ['disabled' => 'disabled']);
$types = Variable::getTypes();
echo $this->render('type/_' . strtolower($types[$model->type]), ['form' => $form, 'model' => $model]);
?>
    <div class="col-xs-12 buttons">
        <?php 
echo Html::a(Yii::t('jlorente/config', 'Return to list'), ['index'], ['class' => 'btn btn-success']);
?>
        <?php 
echo Html::a(Yii::t('jlorente/config', 'Return'), ['view', 'id' => $model->id], ['class' => 'btn btn-info']);
?>
        <?php 
echo Html::submitButton(Yii::t('jlorente/config', 'Update'), ['class' => 'btn btn-primary']);
?>
    </div>
    <?php 
ActiveForm::end();
Exemplo n.º 4
0
 * @license     The MIT License (MIT)
 * @copyright   José Lorente
 * @version     1.0
 */
use yii\grid\GridView;
use yii\grid\ActionColumn;
use yii\data\ActiveDataProvider;
use jlorente\config\models\Variable;
$this->title = Yii::t('jlorente/config', 'Config Variables');
/* @var $model jlorente\config\models\Variable */
/* @var $this yii\web\View */
?>
<div class="backend-container variable-model variable-index clearfix">
    <?php 
$types = Variable::getTypes();
echo GridView::widget(['dataProvider' => new ActiveDataProvider(['query' => Variable::find(), 'pagination' => ['pageSize' => 15]]), 'columns' => ['id', 'code', 'name', ['attribute' => 'type', 'value' => function ($model) use($types) {
    return $types[$model->type];
}], ['attribute' => 'value', 'value' => function ($model) {
    switch ($model->type) {
        /* case Variable::TYPE_ARRAY:
           $v = implode(', ', $model->value);
           break; */
        case Variable::TYPE_OBJECT:
            $v = 'object';
            break;
        default:
            $v = $model->value;
            break;
    }
    return $v;
}], 'created_at:datetime', 'updated_at:datetime', 'updated_by', ['class' => ActionColumn::className(), 'template' => '{view} {update}']]]);