예제 #1
0
 public function search($params)
 {
     $query = Thread::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $this->addCondition($query, 'id');
     $this->addCondition($query, 'title', true);
     $this->addCondition($query, 'body', true);
     $this->addCondition($query, 'created_at');
     $this->addCondition($query, 'created_by');
     $this->addCondition($query, 'updated_at');
     $this->addCondition($query, 'updated_by');
     $this->addCondition($query, 'blog_id');
     $this->addCondition($query, 'root');
     $this->addCondition($query, 'lft');
     $this->addCondition($query, 'rgt');
     $this->addCondition($query, 'level');
     return $dataProvider;
 }
예제 #2
0
<?php

use yii\helpers\Html;
use besnovatyj\blog\models\Thread;
use kartik\tree\TreeView;
$this->title = Yii::t('thread', 'Threads');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="thread-index">

    <h4><?php 
echo Html::encode($this->title);
?>
</h4>
    <?php 
echo TreeView::widget(['query' => Thread::find()->addOrderBy('root, lft'), 'headingOptions' => ['label' => 'Threads'], 'isAdmin' => false, 'displayValue' => 1]);
?>
</div>


예제 #3
0
    <?php 
if (!isset($blog_id)) {
    ?>

    <?php 
    echo $form->field($model, 'blog_id')->widget(Select2::className(), ['data' => ['' => '--- Select ---'] + Blog::options(), 'options' => ['placeholder' => 'Select a state ...', 'multiple' => FALSE], 'pluginOptions' => ['allowClear' => true]]);
    ?>
	<?php 
}
?>

	<?php 
if (!isset($root)) {
    ?>
		<?php 
    echo $form->field($model, 'parent')->dropDownList(['' => \Yii::t('app', '--- Select Parent ---')] + Thread::options());
    ?>
	<?php 
}
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? Yii::t('blog', 'Create') : Yii::t('blog', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>
 /**
  * Finds the Thread model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Thread the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if ($id !== null && ($model = Thread::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getThreads()
 {
     return $this->hasMany(Thread::className(), ['blog_id' => 'id']);
 }
예제 #6
0
?>
<div class="thread-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a(Yii::t('blog', 'Create {modelClass}', ['modelClass' => 'Thread']), ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'title', 'value' => function ($data) {
    return str_repeat('--', $data->depth - 1) . ' ' . $data->title;
}], 'body:ntext', 'created_at:datetime', 'created_by', ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>

<h3>Roots</h3>
<?php 
foreach (Thread::find()->roots()->all() as $item) {
    echo $item->title;
}