Example #1
0
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     $attributes = array_keys($this->getAttributes());
     if (property_exists($this, 'category_id')) {
         $this->isCategory();
     }
     // Upload image
     if (in_array('image', $attributes)) {
         $this->image = \yii\web\UploadedFile::getInstance($this, 'image');
         $ext = FileHelper::getExtention($this->image);
         if (!empty($ext)) {
             $fileDir = Yii::$app->controller->module->id . '/' . date('Y/m/d/');
             $fileName = LetHelper::string_to_url($this->title) . '.' . $ext;
             $folder = Yii::$app->params['uploadPath'] . '/' . Yii::$app->params['uploadDir'] . '/' . $fileDir;
             FileHelper::createDirectory($folder);
             $this->image->saveAs($folder . $fileName);
             $this->image = $fileDir . $fileName;
         }
     }
     // creator, editor and time
     $now = date('Y-m-d H:i:s', time());
     if (in_array('update_time', $attributes)) {
         $this->update_time = $now;
     }
     if (in_array('editor', $attributes)) {
         $this->editor = Yii::$app->user->id;
     }
     if ($this->isNewRecord) {
         if (in_array('creator', $attributes)) {
             $this->creator = Yii::$app->user->id;
         }
         if (in_array('create_time', $attributes)) {
             $this->create_time = $now;
         }
     }
     return parent::beforeSave($insert);
 }
Example #2
0
 public function actionIndex()
 {
     $string = 'Cộng hòa   $##@ xã hội chủ nghĩa Việt Nam';
     echo \app\components\LetHelper::string_to_url($string);
 }
Example #3
0
File: _form.php Project: letyii/cms
?>

<?php 
$form = ActiveForm::begin(['id' => 'formDefault', 'options' => ['enctype' => 'multipart/form-data']]);
echo Html::hiddenInput('save_type', 'save');
echo $form->field($model, 'category_id')->widget(\app\components\FieldCategory::className());
echo $form->field($model, 'title')->textInput(['maxlength' => 255]);
echo $form->field($model, 'content')->widget(letyii\tinymce\Tinymce::className(), ['options' => ['id' => 'testid', 'class' => 'abc'], 'configs' => ['selector' => 'textarea#testid', 'link_list' => [['title' => 'My page 1', 'value' => 'http://www.tinymce.com'], ['title' => 'My page 2', 'value' => 'http://www.tinymce.com']]]]);
echo FieldRange::widget(['form' => $form, 'model' => $model, 'useAddons' => false, 'label' => 'Time range', 'attribute1' => 'from_time', 'attribute2' => 'to_time', 'type' => FieldRange::INPUT_DATETIME]);
//echo $form->field($model, 'from_time')->widget(DateTimePicker::className([
//    'type' => DateTimePicker::TYPE_INPUT,
//    'pluginOptions' => [
//        'autoclose'=>true,
//        'format' => 'dd-mm-yyyy hh:ii'
//    ]
//]));
echo $form->field($model, 'promotion')->widget(SwitchInput::className(['type' => SwitchInput::RADIO]));
echo $form->field($model, 'status')->widget(SwitchInput::className(['type' => SwitchInput::RADIO]));
$imageConfig = ['options' => ['accept' => 'uploads/*'], 'pluginOptions' => ['previewFileType' => 'image', 'showCaption' => FALSE, 'showRemove' => FALSE, 'showUpload' => FALSE, 'browseClass' => 'btn btn-primary btn-block', 'browseIcon' => '<i class="glyphicon glyphicon-camera"></i> ', 'browseLabel' => 'Select Photo']];
if (!empty($model->image)) {
    $imageConfig['pluginOptions']['initialPreview'] = Html::img(LetHelper::getFileUploaded($model->image), ['class' => 'file-preview-image']);
}
echo $form->field($model, 'image')->widget(FileInput::classname(), $imageConfig);
echo $form->field($model, 'author')->textInput(['maxlength' => 255]);
echo $form->field($model, 'source')->textInput(['maxlength' => 255]);
echo $form->field($model, 'seo_url')->textInput(['maxlength' => 255]);
echo $form->field($model, 'intro')->textInput(['maxlength' => 500]);
echo $form->field($model, 'tags')->textInput(['maxlength' => 500]);
echo $form->field($model, 'seo_title')->textInput(['maxlength' => 70]);
echo $form->field($model, 'seo_desc')->textInput(['maxlength' => 160]);
ActiveForm::end();
Example #4
0
File: index.php Project: letyii/cms
    </div>
    <div class="clearfix"></div>
</div>

<div>
    <?php 
echo GridView::widget(['panel' => ['heading' => Yii::t(Yii::$app->controller->module->id, 'Article'), 'tableOptions' => ['id' => 'listDefault']], 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'kartik\\grid\\CheckboxColumn'], ['attribute' => 'id', 'mergeHeader' => TRUE, 'hAlign' => 'center'], 'title', ['attribute' => 'category_id', 'vAlign' => 'middle', 'hAlign' => 'center', 'value' => function ($model, $index, $widget) {
    if (!empty($model->category_id) and is_array($model->category_id)) {
        $result = '';
        foreach ($model->category as $key => $value) {
            $result .= Html::tag('div', Html::a($value->title, '#'));
        }
        return $result;
    }
}, 'filterType' => GridView::FILTER_SELECT2, 'filter' => app\modules\category\models\LetCategory::getCategory('article', '- '), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true]], 'filterInputOptions' => ['placeholder' => 'Tìm theo danh mục'], 'format' => 'raw'], ['attribute' => 'image', 'mergeHeader' => TRUE, 'hAlign' => 'center', 'value' => function ($model, $index, $widget) {
    if (!empty($model->image)) {
        return Html::img(LetHelper::getFileUploaded($model->image), ['class' => 'img-thumbnail']);
    }
}, 'format' => 'raw'], ['attribute' => 'creator', 'vAlign' => 'middle', 'value' => function ($model, $index, $widget) {
    if (isset($model->creatorBy->username)) {
        return Html::a($model->creatorBy->username, ['/member/backend/default/view', 'id' => $model->creatorBy->id], ['title' => 'View author detail']);
    }
}, 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(LetUser::find()->orderBy('username')->asArray()->all(), 'id', 'username'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true]], 'filterInputOptions' => ['placeholder' => Yii::t('member', 'Select user')], 'format' => 'raw'], ['attribute' => 'editor', 'vAlign' => 'middle', 'value' => function ($model, $index, $widget) {
    if (isset($model->editorBy->username)) {
        return Html::a($model->editorBy->username, ['/member/backend/default/view', 'id' => $model->editorBy->id], ['title' => 'View author detail']);
    }
}, 'filterType' => GridView::FILTER_SELECT2, 'filter' => ArrayHelper::map(LetUser::find()->orderBy('username')->asArray()->all(), 'id', 'username'), 'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true]], 'filterInputOptions' => ['placeholder' => Yii::t('member', 'Select user')], 'format' => 'raw'], ['attribute' => 'status', 'class' => '\\app\\components\\BooleanColumn'], ['class' => '\\app\\components\\ActionColumn']], 'responsive' => true, 'hover' => true]);
?>
</div>