Search code examples
phpcakephp-2.4

How populate select box according to the selection of another select box item in cakephp 2.4


I have two models. One is company and another is products. I want to use these models as two separate select boxes. 1st one is company name and another is their products. If I selected company-1, then I need company-1's products in second select box only. How can I do this?


Solution

  • First retrieve all company list from in controller

     $this->Model->find(list);
    

    and show this list in view..

    And make another method in controller like

     find_product($id) 
     { 
         $this->Model->find('list',array('company_id'=>$id)));
     }
    

    or fire ajax on company select list name change and call find_product and pass company id, and update product name with given response by find_product()...