Search code examples
phpfuelphp

Unique Keys/Indexes in FuelPHP


I'm currently undergoing my first venture into FuelPHP and was wondering how I'd go about marking certain keys (e.g. username) in the model, and if it is possible to do so using oil. Particularly in terms of validation in the model, like:

protected static $_properties = array(
  'id',
  'name' => array(
     'data_type' => 'string',
     'label' => 'Name',
     'validation' => array('required', 'max_length'=>array(100), 'min_length'=>array(10)) //validation rules
  ),
  'username' => array(
     'data_type' => 'string',
     'label' => 'Username',
     'validation' => array('required', 'unique') // does this work?
  )
)

Solution

  • That would work, if there was a framework defined validation rule called 'unique'. But there isn't.

    There is an example in the docs (http://docs.fuelphp.com/classes/validation/validation.html#/extending_validation) which explains how to add custom rules, and uses 'unique' as an example.