I’m brand new to Doctrine and Code Igniter and I’m running into a problem with one of my tables.
I have a model that I thought would only allow 4 different letters (for testing at this point in time)
<?php
class Photo extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('photo_path', 'string', 255, array('unique' => 'true'));
$this->hasColumn('category', 'enum', null,
array('values' => array('a', 'b', 'c', 'd'))
);
$this->hasColumn('token', 'string', 255);
}
public function setUp()
{
$this->actAs('Timestampable');
}
public function preInsert($event)
{
$this->token = (sha1(rand(11111, 99999)));
}
}
I have a view that has a select box and an upload form
<?php echo validation_errors('<p class="error">','</p>'); ?>
<div id="upload">
<?php
$categoryOptions= array(
'' => '',
'a' => 'a',
'b' => 'b',
'c' => 'c',
'1' => '1'
);
echo form_open_multipart('admin/addImage');
echo form_upload('userfile');
echo form_dropdown('letter', $categoryOptions);
echo form_submit('upload', 'Upload!');
echo form_close();
?>
</div>
When I select ‘1’ from the select box, I would expect Doctrine to throw an error and not insert that record, however it will insert it with a category of ‘1’. Is there some step I’m not doing so that the enum column restricts the input?
Thanks in advance.
Yes.
Are you sure you have it in the correct place? It should look something like the following, I think:
Column definitions are stored on the table so you can do something like this from within a model instance:
Just for reference sake a
fieldNameis the name of the property on the model and thecolumnNameis the actual name of the column. The two are not always the same so always make sure your passing the expected one when trying to get info from theDoctrine_Table.This could have something to do with emulated versus native
enumtypes, although I’m not sure because I always use native, and it works out. You might try setting native as well:And if that doesn’t do it, you can use one of the validation hooks to ensure it’s in the enumeration.