Results 1 to 2 of 2

Thread: parent Filter?

  1. #1
    New user
    Join Date
    01-05-10.
    Posts
    7

    Default parent Filter?

    i have three tables
    1.product details
    2.brand
    3.categories

    because each manufacturer have different categories, i create the the categories table with 'brand' and 'category' field:
    brand A - category 1a
    brand A - category 2a
    brand B - category 1b
    brand B - category 2b

    in the backend, when edit product detail, i'd like the category field (select field type) to show only value according to what the brand field (also select field type) selected. So when i select 'Brand A' it will only shows 'category 1a' and 'category 2a'. Is it possible to do this without using the Taxonomy module? Is this what the parent Filter for?

    Thanks for the help

  2. #2
    User
    Join Date
    06-19-09.
    Posts
    328

    Default Re: parent Filter?

    You can provide an options_callback for the category field

    the callback should looks like this:

    Code:
    public function listCategory(DataContainer $objDc) {
    
       $brand = $objDc->activeRecord->brand; // assuming your brand field is named brand
    
       // the following depends on how you named your fields :)
       $res     = $this->Database->prepare('SELECT id,name FROM category WHERE brand=?')->execute($brand);
    
       $k        = $res->fetchEach('id');
       $v        = $res->fetchEach('name');
    
       if (is_array($k) && is_array($v)) {
          return array_combine($k, $v);
       }
      
       return array(''=>'no category for the brand');
       
    }
    Consulenza Contao CMS https://www.intco.it

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •