This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

rupert24306
rupert24306

I follwed Ivans Youtube tutorial on Ajax filters and it was very helpful.

As an enhancement, I also want to have different pages showing different item lists.

Currently the initial list of items is set out with the following function in the model file:

   public function scopeListFrontEnd($query, $options=[]){

     extract(array_merge([
       'page' =>1,
       'perPage' =>9,
       'sort' => 'created_at desc',
       'collections' => null,
       'brands' => null,
       'categories' => null

     ], $options));

This returns ALL my items.

On a different page, I would prefer it if the options were like this:

   public function scopeListFrontEnd($query, $options=[]){

     extract(array_merge([
       'page' =>1,
       'perPage' =>9,
       'sort' => 'created_at desc',
       'collections' => null,
       'brands' => null,
       'categories' => 22

     ], $options));

This only returns items in the category with ID 22.

My problem is that this function is in the model file, not the page. So how can I set parameters at the page level to modify this output?

Many thanks!

rupert24306
rupert24306

Ah, I managed this. Had a to take a crash course in PHP hahaha!

In the model I put this:

   public function scopeListFrontEnd($query, $options=[],$catid){
     extract(array_merge([
       'page' =>1,
       'perPage' =>9,
       'sort' => 'created_at desc',
       'collections' => null,
       'brands' => null,
       'categories' => $catid

     ], $options));

and on my page I put this:

  function prepareVars() {
       $options = post('Filter', []);
      $catid = 22;
      $this['items'] = Item::listFrontEnd($options, $catid);
      $this['collections'] = Collection::all();
      $this['brands'] = Brand::all();
      $this['categories'] = Category::all();

  }

Last updated

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.