/**
  * Finds the Fragment model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Fragment the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Fragment::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Fragment::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->type = LuLu::getGetValue('type');
     $query->andFilterWhere(['type' => $this->type]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     //         $query->andFilterWhere([
     //             'id' => $this->id,
     //             'type' => $this->type,
     //         ]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Exemple #3
0
<?php

use yii\helpers\Html;
use yii\helpers\Url;
use source\LuLu;
use source\libs\Constants;
use source\core\grid\GridView;
use source\modules\fragment\models\Fragment;
use source\libs\Resource;
/* @var $this source\core\back\BackView */
/* @var $searchModel source\modules\fragment\models\search\FragmentSearch */
/* @var $dataProvider source\core\data\ActiveDataProvider */
$type = LuLu::getGetValue('type');
$this->title = Fragment::getTypeItems($type);
$this->params['breadcrumbs'][] = $this->title;
$this->toolbars([Html::a('新建', ['create', 'type' => $type], ['class' => 'btn btn-xs btn-primary mod-site-save'])]);
?>
 

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'source\\core\\grid\\IdColumn'], 'code', ['attribute' => 'name', 'width' => '250px', 'value' => function ($model, $key, $index, $column) {
    $indexUrl = Url::to(['fragment' . $model->type . '-data/index', 'fid' => $model->id, 'type' => $model->type]);
    return Html::a($model->name, $indexUrl);
}], ['attribute' => 'description', 'width' => 'auto'], ['class' => 'source\\core\\grid\\ActionColumn', 'width' => '60px', 'template' => '{data-create}{update} {delete}', 'buttons' => ['data-create' => function ($url, $model, $key, $index, $gridView) {
    $addUrl = Url::to(['fragment' . $model->type . '-data/create', 'fid' => $model->id, 'type' => $model->type]);
    return Html::a('<img src="' . Resource::getAdminUrl() . '/images/icons/color/text_signature.png">', $addUrl, ['title' => '添加内容']);
}]]]]);
?>


Exemple #4
0
<?php

use yii\helpers\Html;
use yii\helpers\Url;
use source\LuLu;
use source\libs\Constants;
use source\core\grid\GridView;
use source\modules\fragment\models\Fragment;
/* @var $this source\core\back\BackView */
/* @var $searchModel source\modules\fragment\models\search\Fragment2DataSearch */
/* @var $dataProvider source\core\data\ActiveDataProvider */
$fid = LuLu::getGetValue('fid');
$fragmentModel = Fragment::findOne(['id' => $fid]);
$this->title = $fragmentModel->name . '(静态碎片)';
$this->params['breadcrumbs'][] = $this->title;
$this->toolbars([Html::a('返回', ['fragment/index', 'type' => 2], ['class' => 'btn btn-xs btn-primary mod-site-save']), Html::a('新建', ['create', 'fid' => $fid], ['class' => 'btn btn-xs btn-primary mod-site-save'])]);
?>
 

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'source\\core\\grid\\IdColumn'], ['attribute' => 'title', 'width' => 'auto', 'value' => function ($model, $key, $index, $column) {
    return Html::a($model->title, ['fragment2-data/update', 'id' => $model->id, 'type' => 2, 'fid' => $model->fragment_id]);
}], ['label' => '图片', 'value' => function ($model) {
    return $model->thumb;
}, 'format' => 'image'], ['class' => 'source\\core\\grid\\DateTimeColumn', 'attribute' => 'created_at'], ['class' => 'source\\core\\grid\\SortColumn'], ['class' => 'source\\core\\grid\\StatusColumn'], ['class' => 'source\\core\\grid\\ActionColumn']]]);
?>


</div>
Exemple #5
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     Fragment::clearCachedData($this->fragment_id);
 }
Exemple #6
0
 public static function getFragmentData($code, $options = [], $fromCache = true)
 {
     return Fragment::getData($code, $options, $fromCache);
 }
Exemple #7
0
<?php

use yii\helpers\Html;
use yii\helpers\Url;
use source\LuLu;
use source\libs\Constants;
use source\core\grid\GridView;
use source\modules\fragment\models\Fragment;
/* @var $this source\core\back\BackView */
/* @var $searchModel source\modules\fragment\models\search\FragmentCategorySearch */
/* @var $dataProvider source\core\data\ActiveDataProvider */
$this->title = '分类管理';
$this->params['breadcrumbs'][] = $this->title;
$this->toolbars([Html::a('新建', ['create'], ['class' => 'btn btn-xs btn-primary mod-site-save'])]);
?>
 

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'source\\core\\grid\\IdColumn'], ['attribute' => 'name', 'width' => 'auto'], ['attribute' => 'type', 'width' => '40px', 'content' => function ($model, $key, $index, $gridView) {
    return Fragment::getTypeItems($model->type);
}], ['class' => 'source\\core\\grid\\ActionColumn']]]);
?>


</div>
Exemple #8
0
    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => 64]);
?>

    <?php 
if ($model->isNewRecord) {
    ?>
    <?php 
    echo $form->field($model, 'type')->radioList(Fragment::getTypeItems());
    ?>
    <?php 
} else {
    ?>
    <?php 
    echo $form->field($model, 'type')->reayOnly(Fragment::getTypeItems($model->type));
    ?>
    <?php 
}
?>
    
   
    <?php 
$form->defaultButtons();
?>

    <?php 
ActiveForm::end();
?>

Exemple #9
0
 public static function getFragmentData($fid, $other = [], $fromCache = true)
 {
     return Fragment::getData($fid, $other, $fromCache);
 }