protected function findModel($id)
 {
     if (($model = PostCategory::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = PostCategory::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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->joinWith(['post', 'category']);
     /*$query->andFilterWhere([
           'post_id' => $this->post_id,
           'category_id' => $this->category_id,
       ]);*/
     $query->andFilterWhere(['like', 'post_title', $this->post_id])->andFilterWhere(['like', 'category_name', $this->category_id]);
     return $dataProvider;
 }
示例#3
0
 public function getCategory()
 {
     return $this->hasOne(PostCategory::className(), ['id' => 'cate_id']);
 }
示例#4
0
use yii\bootstrap\ActiveForm;
use app\models\PostCategory;
?>

<div id="post-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => 255]);
?>
    
    <?php 
echo $form->field($model, 'cate_id')->dropDownList(PostCategory::listCategories());
?>

    <?php 
echo $form->field($model, 'thumbnail', ['inputOptions' => ['id' => 'browse-img'], 'inputTemplate' => '<div class="input-group">{input}<span class="input-group-btn"><button type="button" id="browse-btn" class="btn btn-default"><i class="fa fa-search"></i></a></span></div>'])->textInput(['maxlength' => 255]);
?>
    
    <?php 
echo $form->field($model, 'description')->textarea();
?>

    <?php 
echo $form->field($model, 'content')->textarea(['id' => 'tiny-area']);
?>

    <?php 
 public function run()
 {
     $postCategory = PostCategory::create(['parent_id' => null, 'lft' => 1, 'rgt' => 2, 'depth' => 0, 'active' => 1, 'slug' => 'root', 'name' => 'Root']);
 }
 /**
  * move resources
  *
  * @param  int $id
  *
  * @return Response
  */
 public function move($id)
 {
     $validator = Validator::make(Input::all(), ['parent_id' => 'exists:post_category,id']);
     if ($validator->fails()) {
         throw new ResourceException($validator->errors()->first());
     }
     if (is_null($category = PostCategory::find($id))) {
         return $this->postCategoryPresenter->errorNotFound();
     }
     if (Input::has('parent_id')) {
         $dest = PostCategory::find(Input::get('parent_id'));
     } else {
         $dest = PostCategory::root();
     }
     if (!is_null($next = Input::get('next_id'))) {
         $next = PostCategory::find(Input::get('next_id'));
     }
     if (!is_null($prev = Input::get('prev_id'))) {
         $prev = PostCategory::find(Input::get('prev_id'));
     }
     // dest = null, move to parent
     // dest = null, next = null, move to parent and last
     if (is_null($dest) && is_null($next) && !is_null($prev)) {
         //move to parent and last
         $category->moveToRightOf($prev);
     } else {
         if (is_null($dest) && !is_null($next)) {
             //move to parent
             $category->moveToLeftOf($next);
         } else {
             if (!is_null($dest) && is_null($next)) {
                 $category->makeLastChildOf($dest);
             } else {
                 //move to parent
                 $category->moveToLeftOf($next);
             }
         }
     }
     return response()->return();
 }
示例#7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPostCategories()
 {
     return $this->hasMany(PostCategory::className(), ['category_id' => 'id']);
 }
示例#8
0
 /**
  * List all post categorys
  *
  * @return response
  */
 public function index()
 {
     $postCategories = PostCategory::all();
     return view('backend::post_category.index', ['post_categories' => $postCategories]);
 }