Search code examples
codeignitergrocery-crud

Grocery crud set_relation


$crud->set_relation('seo_url', 'db_projects','seo');

On insert/update crud add id (primary key ) from db_projects to seo_url field. How can I add seo from db_projects not id (primary key) to seo_url field?


Solution

  • For this situation I think the only solution is to actually create a custom dropdown list with field_type method. So in your case you will have:

    $seo_results = array();
    foreach ($this->db->get('db_projects')->result() as $row) {
        $seo_results[$row->seo] = $row->seo;
    } 
    $crud->field_type('seo_url', 'dropdown', $seo_results);