[Solar-talk] table_cols require field
Jeff Surgeson
solar at 3hex.com
Sun Nov 4 08:00:55 CST 2007
Hi Rodrigo
> > If a table field is defined as require in _table_cols in a data model for
> It seems that this changed a little bit: 'require' is mainly used to
> create the table. Once it is created, the model will consider the
> column required if its default value is not NULL (in the database, not
> in the model definitions). To make it required *after* the table was
> created, you have to manually change your table and set the default
> value for the field to NULL.
Thanks for that makes sense!
Trying to convert my code to work with the latest svn, having a problem with
file & select form types, I have a table model all set up and defined, save
delete etc works fine, I need to define two fields as file and select as
below, which works however I cant set the form value so it saves the value
from the form, I know I am being blonde but what am I missing, my add()
action below.
public function actionAdd()
{
// which record cols do we want to work with?
$cols = array('image', 'main_cat');
// get a blank item, then populate with submitted data
$item = $this->_gallery->fetchNew();
$data = $this->_request->post('gallery', array());
$item->load($data, $cols);
// save?
if ($this->_isProcess('save')) {
try {
$item->save();
$this->_session->setFlash('add_ok', true);
$this->_redirect("gallery/edit/{$item->id}");
} catch (Solar_Sql_Model_Record_Exception_Invalid $e) {
// do nothing, the item form will show invalids
}
}
// get the form from the record
$form = $item->form($cols);
$form->setElements(array(
'gallery[image]' => array(
'type' => 'file',
'value' => $item->image,
),
'gallery[main_cat]' => array(
'type' => 'select',
'value' => $item->main_cat,
'options' => array('weddings', 'babies'),
),
));
// assign data for the view, and done
$this->formdata = $form;
}
--
...........::::::...........
Jeff Surgeson / South Africa
More information about the Solar-talk
mailing list