Re: filling an array for a selectbox (v1.2)
I know that, but the data does not come from my database, but from an API that delivers it in a specific format. I just need to know what I have to do with the $issuerArray to turn it over to another array that I can return to the controller that is calling this component and from there use it to fill my selectbox in the view. The $issuerArray looks like this: Array ( [0] = IssuerBean Object ( [issuerID] = 0151 [issuerName] = Issuer Simulator [issuerList] = Short ) ) The best thing I've come to is this: --- in my component function doDirectoryrequest(): --- for($i = 0; $i count($issuerArray); $i++) { $keys[$i] = $issuerArray[$i]-issuerID; $values[$i] = $issuerArray[$i]-issuerName; } $issuers = array_combine($keys, $values); return $issuers; --- in my controller: --- $this-set('result', $this-Ideal-doDirectoryrequest()); --- in my view: --- ?php echo $form-select('issuer', array('options' = $result, array(), array(), false)); ? --- This is resulting in this html code: select name=data[issuer] id=issuer option value=/option optgroup label=options option value=0151Issuer Simulator/option /optgroup optgroup label=1 /optgroup option value=2/option /select But somehow there's a lot of stuff in there I don't want to have. I just need this : select name=data[issuer] id=issuer option value=0151Issuer Simulator/option /select --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: filling an array for a selectbox (v1.2)
Have you tried Set::combine($issuerArray, '{n}.issuerID', '{n}.issuerName' ); On 2/24/08, Ronald [EMAIL PROTECTED] wrote: I know that, but the data does not come from my database, but from an API that delivers it in a specific format. I just need to know what I have to do with the $issuerArray to turn it over to another array that I can return to the controller that is calling this component and from there use it to fill my selectbox in the view. The $issuerArray looks like this: Array ( [0] = IssuerBean Object ( [issuerID] = 0151 [issuerName] = Issuer Simulator [issuerList] = Short ) ) The best thing I've come to is this: --- in my component function doDirectoryrequest(): --- for($i = 0; $i count($issuerArray); $i++) { $keys[$i] = $issuerArray[$i]-issuerID; $values[$i] = $issuerArray[$i]-issuerName; } $issuers = array_combine($keys, $values); return $issuers; --- in my controller: --- $this-set('result', $this-Ideal-doDirectoryrequest()); --- in my view: --- ?php echo $form-select('issuer', array('options' = $result, array(), array(), false)); ? --- This is resulting in this html code: select name=data[issuer] id=issuer option value=/option optgroup label=options option value=0151Issuer Simulator/option /optgroup optgroup label=1 /optgroup option value=2/option /select But somehow there's a lot of stuff in there I don't want to have. I just need this : select name=data[issuer] id=issuer option value=0151Issuer Simulator/option /select --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: filling an array for a selectbox (v1.2)
I just tried that. Now I don't need the for loop, but it still gives me the same result. On 24 feb, 14:38, Dardo Sordi Bogado [EMAIL PROTECTED] wrote: Have you tried Set::combine($issuerArray, '{n}.issuerID', '{n}.issuerName' ); On 2/24/08, Ronald [EMAIL PROTECTED] wrote: --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: filling an array for a selectbox (v1.2)
Try this at your component: var $issuers = array(); function doDirectoryrequest() { $issuerArray = array('YOUR DATA'); foreach($issuerArray as $issuer) { $this-issuers[$issuer['issuerID']] = $issuer['issuerName']; } return $this-issuers; } And keep your controller and view the same. Johan de Jong On 24 feb, 14:24, Ronald [EMAIL PROTECTED] wrote: I know that, but the data does not come from my database, but from an API that delivers it in a specific format. I just need to know what I have to do with the $issuerArray to turn it over to another array that I can return to the controller that is calling this component and from there use it to fill my selectbox in the view. The $issuerArray looks like this: Array ( [0] = IssuerBean Object ( [issuerID] = 0151 [issuerName] = Issuer Simulator [issuerList] = Short ) ) The best thing I've come to is this: --- in my component function doDirectoryrequest(): --- for($i = 0; $i count($issuerArray); $i++) { $keys[$i] = $issuerArray[$i]-issuerID; $values[$i] = $issuerArray[$i]-issuerName; } $issuers = array_combine($keys, $values); return $issuers; --- in my controller: --- $this-set('result', $this-Ideal-doDirectoryrequest()); --- in my view: --- ?php echo $form-select('issuer', array('options' = $result, array(), array(), false)); ? --- This is resulting in this html code: select name=data[issuer] id=issuer option value=/option optgroup label=options option value=0151Issuer Simulator/option /optgroup optgroup label=1 /optgroup option value=2/option /select But somehow there's a lot of stuff in there I don't want to have. I just need this : select name=data[issuer] id=issuer option value=0151Issuer Simulator/option /select --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: filling an array for a selectbox (v1.2)
Anyway ... Say you have a table, 'regions', with columns 'id' 'name': $this-set('regions', $this-Region-find('list')); Or, if this is an associated model: $this-set('regions', $this-Country-Region-find('list')); View: ?= $form-select('Country.region', $regions, null, array(), true) ? Use different column name: $this-Country-Region-displayField = 'name_en'; $this-set('regions', $this-Country-Region-find('list')); On Sat, Feb 23, 2008 at 6:52 PM, b logica [EMAIL PROTECTED] wrote: On Sat, Feb 23, 2008 at 2:59 PM, Ronald [EMAIL PROTECTED] wrote: It's probably something simple, but I'm trying to figure this out for a few hours now and I just can't get it right. I'm building a component and one function needs to return an array I can use to fill a selectbox. This return array needs to be filled from an array of objects,. This is my loop to walk trough the array of objects. --- for($i = 0; $i count($issuerArray); $i++) { //$issuerArray[$i]-issuerID - this needs to be the id of every option //$issuerArray[$i]-issuerName; - this needs to be the value of every option } --- My question is how to get these values into a array (the return array) in such a way that I can use it to fill an selectbox. I tried several things but I allways end up with a selectbox with all kind of strange values in it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: filling an array for a selectbox (v1.2)
On Sat, Feb 23, 2008 at 2:59 PM, Ronald [EMAIL PROTECTED] wrote: It's probably something simple, but I'm trying to figure this out for a few hours now and I just can't get it right. I'm building a component and one function needs to return an array I can use to fill a selectbox. This return array needs to be filled from an array of objects,. This is my loop to walk trough the array of objects. --- for($i = 0; $i count($issuerArray); $i++) { //$issuerArray[$i]-issuerID - this needs to be the id of every option //$issuerArray[$i]-issuerName; - this needs to be the value of every option } --- My question is how to get these values into a array (the return array) in such a way that I can use it to fill an selectbox. I tried several things but I allways end up with a selectbox with all kind of strange values in it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---