Search

Hi All,

I'm just experimenting a little with data sources. Trying to filter entries based on categories and subcategories.

To do this I simply use the SBL field. In wich you can select a category and a subcategory. In the datasource I have a filter filtering the SBL like this:

{$category} + {$subcategory}

After I fixed the plus bug, this works ok. But if no params are given in the url, no results are returned. I want all entries listed if the params are empty. Right now I have fixed this by altering the datasource manually in the execute function like this:

if(empty($this->_env['env']['url']['category']) &&
           empty($this->_env['env']['url']['subcategory'])) {
            unset($this->dsParamFILTERS);
        }

This works, when there are no url segments for the variables category and subcategory all entries are displayed. But I'm wondering if there is anything I can add to the filter to do the same?

If I understand well, all this can be natively done with the Symphony's back-end datasource interface.

But, on a second thought, you maybe want to construct it with Symphony's API by yourself? OK, with this one I personaly can not help you.

Anyway, bump this thread if you want to help out with the former - build-in way. Good luck.

You can leave "Required URL Parameter" empty if you want to return all entries when none param sent.

Hi, the required url params field is empty. Bit no results are returned without the manual change to the .php datasource. I might be dealing with another bug here.

Hi, I did it this way:

  1. Had a section with a field Category and a field Subcategory,
  2. For the datasource (DS) I added two filters: one for field Category filtered by parameter {$category}, the second for field Subcategory filtered by {$subcategory}.

Thats it, works well. All other DS settings are default - I've only picked the fields for DS output, and you can also set the Pagination size as you need.

Maybe you have all of this too, sorry, but I was a bit puzzled of that {$category} + {$subcategory} filtering setup you'd mentioned a also that you had been fixing it.

What Symphony version do you use?

Hi Juro,

Thanks for your explanation. I may have to describe what I did a little better :). My setup is as follows:

1: I have just one SBL field in wich you can select a category and a subcategory. 2: I have one filter in the DS for this field that combines the two parameters: {$category} + {$subcategory}. The + is for AND in the query.

All other settings are the default DS settings, no required parameters or anything.

This works, but not when there are no parameter values. It works in this scenario: www.website.com/category-1 it also works in this scenario: www.website.com/category-1/subcategory-1 but it doesn't work when it's just www.website.com. No results are shown at all while I would want de DS to return all results for that section.

I did come up with a solution by altering the .php file for the datasource in the execute() function. It was simple enough, but it felt like it should be possible without writing php in the DS, that's why I asked if there is another way.

Using two SBL fields might work, but I would rather just use one, else I wouldn't know why you have the option to link multiple sections in one SBL field anyway.

Hopefully this makes things clearer?

I was thinking. Maybe the DS is not returning any results because internally the filter isn't really empty. It's a 'space'+'space'. There is nothing to return on that filter.

I have filed an issue for this, it may be something that needs to be fixed: https://github.com/symphonycms/symphony-2/issues/1759

Hi Sanity11,

I have filed an issue for this, it may be something that needs to be fixed

EDIT: nice finding :)

OK, as of me (a non programmer), with all this info, I would reconsider your section's data architecture to use the two fields as I mentioned them.

Maybe this is the turning view point:

... the option to link multiple sections in one SBL field anyway...

This is to be multiple options .... When selecting multiple options, they are taken as OR values for a field, whereas multiple fields given for a DS filter are taken as an AND condition between each other in the final DS filter. So you get field-1 AND field-2.

With two fields, you will have no trouble to filter and represent your data in the www.website.com/category-1/subcategory-1 manner.

Section's data structure is the key to all other Symphony's features. I play with it all the time, finding slowly small improvements there. Still kind of a learner.

Hope you get along! I will follow the results.

Hi Juro, thanks. Your probably right about having two fields. Nevertheless I think the + operator shouldn't break the results in the scenario I have described :).

Yes, I agree about that, thanks for reporting that issue. Thanks also for that further info about your setup, made things clear for me :)

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details