In case you've missed it, you are looking at an older version of the website. Checkout our latest version, we promise you will love it 😍


void set_model( string $model_as_string );
Quick Description: Sets the model that crud will use ( The model always must extends grocery_Model )

Sets the model that crud will use .The model always must extends grocery_CRUD_Model . grocery_CRUD_Model extends CI_Model so you don't have to be afraid to use it.

Below I explain with steps how you can use the set_model

1st STEP - go to your basic function and add your custom model

function just_an_example()
    $crud = new grocery_CRUD();
    $crud->set_relation_n_n('actors', 'film_actor', 'actor', 'film_id', 'actor_id', 'fullname','priority');  
    $output = $crud->render();

2nd STEP-Your custom model MUST extend grocery_CRUD_Model. So create a new file at application/models/my_custom_model.php and it will be something like this:

class My_Custom_model extends grocery_CRUD_Model  {
    function get_relation_n_n_unselected_array($field_info, $selected_values)
        $selection_primary_key = $this->get_primary_key($field_info->selection_table);
        if($field_info->name = '....')
            .......your custom queries
        $results = $this->db->get($field_info->selection_table)->result();
        $results_array = array();
        foreach($results as $row)
                $results_array[$row->{$field_info->primary_key_alias_to_selection_table}] = $row->{$field_info->title_field_selection_table}; 
        return $results_array;        

The set_model function is good because you don't have to change the core of grocery crud. You can create whatever model you like if you just want to do more complicated queries.

For another example you can also see a full working example of using the set_model »