Thanks for the response.

It kind of worked.  I went into IRC and Dakota had helped me with it.
Here is how it was fixed, if others are having the same issue...

<?php
//Division model

public function getDivAndGroups() {
    $virtualFieldSave = $this->virtualFields;  //Save the existing
virtualFields array

    $this->virtualFields = array(
        'divandgroup' => 'CONCAT(Division.division, " ",
Division.group)' //Add a new virtualField for this model
    );

    $divisions = $this->find('list', array(
        'fields' => array('Division.id', 'divandgroup'), //Always
reference fields with the model name, virtualFields don't get it
        'order' => array('divandgroup' => 'ASC') //You can order by
virtual fields as well
    );

    $this->virtualFields = $virtualFieldSave; //Restore original
virtualFields array

    return $divisions; //Return result
}

//RepresentativesController

public function add() {
    if (!empty($this->data)) {
            if ($this->Representative->save($this->data)) {
                    $this->Session->setFlash('Your Representative has
been saved.');
                    $this->redirect(array('action' => 'index'));
            }
    }
    $this->set('divisions', $this->Representative->Division-
>getDivAndGroups()); //Put this after the save call, no use running a
sql query if you are going to redirect the user away from this page.
}



=================

On Apr 30, 5:01 pm, DigitalDude <[email protected]> wrote:
> Hey,
>
> first thing to check is a pr($divisions) in your controller to check
> if the data from your find()-call is correct (and your virtual field
> is included).
>
> Second thing is that a select as I remember should look like this
> within a view:
>
> echo $this->Form->input(__('Division', true), array(
>     'type' => 'select',
>     'options' => divisions
> );
>
> Your code looks a bit confusing when it comes to the view.
> Normally when your array for the Drop-Down-Options is formatted well,
> you do not need to set $divisions variable within the options of the
> select input.
>
> So I guess your list array (e.g. $key => $value pairs) is not correct
> formatted.
>
> Could you post the pr()-result of your $divisions array here?
>
> Regards,
>
> DD

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to