Thursday, April 28, 2011

Help with virtualFields

Hi!

I'm trying to concat two fields together in a database query. I've
read that virtualFields is the way to go with the new versions. The
problem I'm having is that the view doesn't populate the drop down
box. The box has all the fields available, but no text goes with the
fields...it's kind of like "invisible text". What I want to do is
join "division + group" to make it one field.

Here is the part in my model....

---cut---
function _setDivisions() {
$virtualFields = array(
'divandgroup' => 'CONCAT(Division.division, " ",
Division.group)'
);
$divisions = $this->Representative->Division->find
(
'list',
array
(
'fields' => array('id', $virtualFields['divandgroup']),
'order' => 'Division.division ASC'
)
);
$this->set(compact('divisions'));
}

function add() {
$this->_setDivisions();
if (!empty($this->data)) {
if ($this->Representative->save($this->data)) {
$this->Session->setFlash('Your Representative has been saved.');
$this->redirect(array('action' => 'index'));
}
}
}
---cut----

Here is what I have in my view

---cut----
echo $form->select(
'Representative.division_id',
$divisions,
null,
array(),
false
);
---cut----


I've tried a number of things and can't seem to get it to work. Any
help would be appreciated!

Thanks!

--
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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: