<?phpclass Categorymodel extends Model { var $id = 0; function Categorymodel() { parent::Model(); } /** * Save new category into database */ function save( $category ) { if( !is_array($category) ) return; //check if we have a parent if( sizeof( $category ) > 2 ) { if( $this->byID( $category['parent'] ) == false ) { $category['parent'] = 0; } } //lets check if its a child or not if( $category['child'] == 0 ) { $category['parent'] = 0; } //save the data $this->db->insert("category",$category); } /** * Category By ID * * Gets category from database, returns true if category exists * return boolean */ function byID( $id ) { $query = $this->db->get_where("category",array('id' => $id)); if( $query->num_rows() == 0 ) return false; return true; }}/* END OF FILE */