Saturday, 15 January 2011

php - Yii Dynamic Listbox -


Currently in Yii I have an AJAX call on a list box that will dynamically modify the next box on selection.

Ajax call currently indicates my controller and method. Public Function Action Dynamic Products () {Forrest ($ _ POST ['product group'] ['id'] $ product group) {$ Grouped P = Grouped Product :: Models () - & gt; FindAll ('product_group_id =: product_group_id', array (': product_group_id' = & gt; $ product group)); $ GroupedP = CHTML :: listData ($ groupedP, 'id', 'product_id'); Foreign Currency ($ grouped P $ value = & gt; $ product_id) {$ data = product :: model () - & gt; Search (all '(id =: id', array (': id' => $ product_id)); $ data = CHTML :: listData ($ data, 'id', 'title'); foreign currency ($ Value = $ as data $ & gt; $ headline} {echo CHtml :: tag ('option', array ('value' = & gt; $ value), CHtml :: encoded ($ title), true);}} }}

Currently it works perfectly well, but what I want to do for this is reverse where a group is selected, the next box is related to that I do not show the products. $ data = products :: model () - & gt; findAll ('id! =: Id', array (': id' => $ product_id)); But if there are multiple items This will not be displayed only which is not available for example

  $ product = array (0 = & gt; relationship1 => shirts2 = & gt; jeans) $ group product = Array (0 = & gt; Shirts and Jeans 1 = & gt; Relationship2 = Jeans and Connection)   

If I select shirts and jeans, then just show me Should show relationship. Or if I choose shirts and jeans Literacy, my relationship should not show anything.

There is a mistake in your logic that generates a set of tags for each repeat option of your first 'foreach' Example:

  1. You choose: Shirts and jeans, tie
  2. The first currency of the foreign exchange meets the 'Shirts and Jeans' product group and displays the Ties option.
  3. From the second trip of foreign exchange, 'tie' becomes a product group and displays shirts and jeans options.

    To do this, you can fix it:

      // status whith not absolute $ dbc = new CDBCRIIT (); $ Dbc- & gt; Adet Incandesence ('product_group_id', $ _POST ['product group'] ['id']); $ GroupedP = GroupedProducts :: Model () - & gt; FindAll ($ DBC); $ GroupedP = CHTML :: listData ($ groupedP, 'id', 'product_id'); Foreign Currency ($ grouped P $ value = & gt; $ product_id) {$ data = product :: model () - & gt; Search (all '(id =: id', array (': id' => $ product_id)); $ data = CHTML :: listData ($ data, 'id', 'title'); foreign currency ($ Value = $ as data $ & gt; $ headline} {echo CHtml :: tag ('option', array ('value' = & gt; $ value), CHtml :: encoded ($ title), true);}}   

    Hope this will help you.

No comments:

Post a Comment