Grant,

Thanks for the tip.    I must be doing something subtly wrong with
your suggestion.   I set the $this->data['Display']['currency'] in my
index controller method.   When adding the echo $html-
>checkbox( 'Display/currency' ); I get "Cannot instantiate non-
existent class: display ".    Initially my index view did not contain
a form.   I added the following form, but I still get the "non-
existent class: display"   notification

    <form action="<?php echo $html->url('/proposals/index'); ?>"
method="post">

I've get the currency toggle working, but my method appears to be a
bit cumbersome.

1. Place a Ajax observer field on a standard HTML checkbox

echo $ajax->observeField('currency', array(
                                'update' => 'proposalCurrency',
                                'url' => '/proposals/ajaxCurrency',
                                'frequency' => '1'))

<dd><input type="checkbox" id="currency" name="currency" value="EUR"
<?php
    if (strcmp ($currency, "EUR") == 0)
       echo " CHECKED ";
?>></input></dd>
</dl>

2. Move the table containing the Price column which will be either EUR
or USD into a separate  table.thtml file
   this table is embedded with the <div id="proposalCurrency">

3. In the index method of the proposal controller set the "currency"
variable
             $this->set('currency', $whichCurrency);   //
whichCurrency will be either the string "EUR" or "USD"

4. In the  proposal controller ajaxController, the currency from the
form is retrieved with the   $this->params['form']['currency']

              if (isset($this->params['form']['currency']) &&
                strcmp ($this->params['form']['currency'],"EUR") == 0)
                $whichCurrency = "EUR";
            else
            {
               $whichCurrency = $this->Session->read
("Proposal.whichCurrency");
               $whichCurrency = (strcmp($whichCurrency, "USD") == 0) ?
"EUD" : "USD";
            }

5.  Session variables were used to maintain the users currency
selection preference.

My solution does work, but it does not seem to be efficient or
elegant.   Any suggestions on why I can't use ['Display']['currency']
in the view with the $html->checkbox helper would be appreciated.



On Feb 7, 10:02 pm, "Grant Cox" <[EMAIL PROTECTED]> wrote:
> I personally find the best way is still using the html / form helpers,
> but to use a model or field name that doesn't exist.  Of course, if
> you want the value to persist then you'll need to store the value
> somewhere - perhaps in the session.
>
> ie, in your controller:
>
> function edit($id = null) {
>         if(empty($this->data)) {
>                 ...
>                 $this->data['Display']['currency'] = 
> $this->Session->read('Display.currency');
>
>         } else {
>                 $this->cleanUpFields();
>                 // save the currency they selected back to the session
>                 $this->Session->write('Display.currency', 
> $this->data['Display']
> ['currency']);
>
>                 ...
>         }
>
> }
>
> and your view can just use
> echo $html->checkbox( 'Display/currency' );


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to