Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Boolean and date fiel type, what is the best practice?
  • Hi all!
    Some questions from novice: $ oil generate admin posts title:string slug:string summary:text body:text publish:boolean published_at:date After CRUD generation I see in a form, boolean and date fields displayed as regular text inputs, not as checkbox and datepicker as expected. This feature not implemented yet? After changing Form::input to Form::checkbox I got error on saving record, boolean field publish cannot be null(if checkbox not checked) I did small modification to fix this problem:
      <?php echo Form::hidden('publish', '0'); ?>
      <?php echo Form::checkbox('publish', Input::post(
                    'publish', 
                    isset($post) ? $post->publish : '0'), 
                    array('class' => 'span6', 'checked' => (isset($post) && $post->publish) ? 'checked' : 'false')
      ); ?>
    

    Is it the best way?
    Why migration did boolean field as tinyint and NULL by default? Thanks!
  • I'll answer some of your questions, Oil isn't really my area.
    After changing Form::input to Form::checkbox I got error on saving record, boolean field publish cannot be null(if checkbox not checked)
    Why migration did boolean field as tinyint and NULL by default?
    When a checkbox isn't checked it won't show up in the $_POST array at all (not even as a key with empty value), thus Input::post('publish') will return null.
    This is where your post gets a bit ambiguous as the error it results in means the field is NOT NULL but you say it will allow NULL? I guess it's a typo, thus the field is not-null which seems logical to me.
    As to it being "TINYINT(1)", that's because mysql doesn't have a boolean type. BOOL or BOOLEAN is just an alias for TINYINT(1) which can be either 0 or 1.
  • Jelmer: thanks for your answer, could you give me you snippet for boolean field?
    Model, validator and form widget. Thank you!
  • Not sure what you want, there's not much difference between a boolean field and another field. How you implement is up to you.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion