Unify 2 requests for action, yii2



  • Hello, I have a question. I make an album with categories and subcategories. On the first page, all categories, when the images of this category are opened. How to make sure that when pressed in the ekshine, there is also a substitution of the category and photo of the category in question, similar to the veindows folder.

    That's the kind of action code.

    $query = Content::find()
            ->select('content.*')
            ->with('category')
            ->where(['category_id' => $id]);
    
    $pagination = new Pagination(['totalCount' => $query->count(), 'pageSize'=>6]);
    $dataProvider = new ActiveDataProvider([
        'query' => $query,
        'pagination' => $pagination
    ]);
    return $this->render('album', [
        'dataProvider' => $dataProvider,
        'pagination' => $pagination,
    ]);
    

    This is the conclusion.

    введите сюда описание изображения

    It's necessary to remove the category images and subsidiaries (if any)

    So I need something like that code.

    $query = Category::find()
    ->from('category')
    ->where(['parent_id' => $id]);

    Checking out his daughter's category.
    But here's how this request is to get off first, and how I don't know, the withdrawal code.

    <div class="row">
    <?php
    foreach ($models as $model) { ?>
    <div class="col-sm-6 col-md-4">
    <div class="thumbnail">
    <a href="/content/view?id=<?= $model->id?>">
    <img src="<?= '/backend/web/'.$model->content_image ?>" alt="image" width="400" height="400" class="img-rounded">
    </a>
    </div>
    </div>
    <?php } ?>
    </div>
    </div>

    Who thinks? Is it possible that you once did this?



  • What if we do it through a connection? I'm not sure if it's gonna work. In model Category

    public function getChildren()
    {
        return $this->hasMany( Category::className(), ['parent_id' => 'id'] );
    }
    

    Then daughters will be available as

    $category->children
    

    I'm recommending that we use it. https://github.com/creocoder/yii2-nested-sets ♪




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2