⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

searching tinyint field (true_false)



fractorr
  • profile picture
  • Member

Posted 29 March 2016 - 22:59 PM

I purchased the bootstrap theme and I have a field called active which is a tinyint field with a length of 1 which I use the $crud->field_type('active', 'true_false', array("No", "Yes")); so that it displays Yes / No instead of active / inactive.  This all works great until I try and search on the field, if I enter 1 to search on it works as expected but if I enter 0 to search it does not filter out any records even though there are server records with active set to 0.

 

Anyone come across this and if so any idea how to fix this?

 

 


fractorr
  • profile picture
  • Member

Posted 29 March 2016 - 23:24 PM

So this was my fix for this issue, probably not the best way to go about it since it is modifying core code but it seems to work.  I modified the Grocery_crud_model.php file and changed the like function to this.

    function like($field, $match = '', $side = 'both')
    {
    	if ($match == 0) {
		$this->db->where($field, 0);
	} else {
	    	$this->db->like($field, $match, $side);
	}
    }


fractorr
  • profile picture
  • Member

Posted 29 March 2016 - 23:44 PM

So I just read up on extending GC, pretty cool.  I created this model and it used the set_model function and it seems to work just fine now and now I am not modifying core code. :)

<?php
class Grocery_crud_model_gdbl  extends Grocery_crud_model  {
    function like($field, $match = '', $side = 'both')
    {
    	if ($match == 0) {
		$this->db->where($field, 0);
	} else {
	    	$this->db->like($field, $match, $side);
	}
    }
}