⚠ 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

read fields



ghizlan

ghizlan
  • profile picture
  • Member

Posted 25 May 2015 - 10:48 AM

Hi every one ,

 

 

the read action shows me all the fields exists in  my table (database) , I want to show only the fields that I had specified in $crud->columns.

 

Sorry for my english.


Paul Savostin

Paul Savostin
  • profile picture
  • Member

Posted 02 June 2015 - 11:21 AM

Hi!  
Set read fields same you specified in $crud->columns() like this one

$crud
->columns('field1','field2')
->set_read_fields('field1','field2');


fede72bari

fede72bari
  • profile picture
  • Member

Posted 22 July 2020 - 15:34 PM

Does anybody have tested set_read_fields? This what i get with a callback function after setting a new custom field in read:

 

ERROR - 2020-07-22 17:26:28 --> Severity: Notice --> Undefined index: officies_location /home/phar263d/public_html/adminPanel/application/libraries/Grocery_CRUD.php 4477

ERROR - 2020-07-22 17:26:28 --> Severity: Notice --> Trying to get property of non-object /home/phar263d/public_html/adminPanel/application/libraries/Grocery_CRUD.php 4477
ERROR - 2020-07-22 17:26:28 --> Severity: Notice --> Undefined index: officies_location /home/phar263d/public_html/adminPanel/application/libraries/Grocery_CRUD.php 2939
ERROR - 2020-07-22 17:26:28 --> Severity: Warning --> Creating default object from empty value /home/phar263d/public_html/adminPanel/application/libraries/Grocery_CRUD.php 2950
ERROR - 2020-07-22 17:26:28 --> Severity: Notice --> Trying to get property of non-object /home/phar263d/public_html/adminPanel/application/libraries/Grocery_CRUD.php 2953
ERROR - 2020-07-22 17:26:28 --> Severity: Notice --> Undefined property: stdClass::$display_as /home/phar263d/public_html/adminPanel/assets/grocery_crud/themes/bootstrap-v4/views/read.php 39
 

Here the code

 

        $this->grocery_crud->add_fields('id','vendor_name','vendor_web_site_url','default_currencies_id','affiliation_category','external_affiliation_services_id','affiliation_vendor_id','remark','last_modified','creation','enabled');
        $this->grocery_crud->edit_fields('id','vendor_name','vendor_web_site_url','default_currencies_id','affiliation_category','external_affiliation_services_id','affiliation_vendor_id','remark','last_modified','creation','enabled');  
        $this->grocery_crud->set_read_fields('id','vendor_name','vendor_web_site_url','default_currencies_id','affiliation_cate...gory','external_affiliation_services_id','affiliation_vendor_id','remark','last_modified','creation','enabled','officies_location');

[...]

 

 
        $this->grocery_crud->callback_read_field('officies_location',array($this,'_callback_officies_location'));

and the call back function that is fine (tested):

   public function _callback_officies_location($value, $primary_key)
    {
        
   
        $this->db->where('vendors_id', $primary_key);    
        $this->db->join('countries', 'countries.id = country');
        $this->db->join('people', 'people.id = reference_people_id');
        $this->db->order_by('vendors_id', 'ASC');  
        
        $query_res = $this->db->get('vendor_office_locations');

        $officies_locations_list = '';
        foreach ($query_res->result() as $row){


                $officies_locations_list .= '
                
                <div class="table-label">
                    <div class="floatL l5">'.
                        $row->name.'
                    </div>
                    <div class="clear"></div>
                </div>
                <div class="form-container table-container">
                    <div class="form-group row">
                        <label class="col-sm-3 control-label">
                                City:
                        </label>
                        <div class="col-sm-9 read-row">
                            <div id="field-vendor_name" class="readonly_label">'.
                                $row->city.'
                            </div>                            
                        </div>
                    </div>
                    
                    <div class="form-group row">
                        <label class="col-sm-3 control-label">
                                ZIP:
                        </label>
                        <div class="col-sm-9 read-row">
                            <div id="field-vendor_name" class="readonly_label">'.
                                $row->zip.'
                            </div>                            
                        </div>
                    </div>
                    
                    <div class="form-group row">
                        <label class="col-sm-3 control-label">
                                Address:
                        </label>
                        <div class="col-sm-9 read-row">
                            <div id="field-vendor_name" class="readonly_label">'.
                                $row->address.'
                            </div>                            
                        </div>
                    </div>     
                    
                    <div class="form-group row">
                        <label class="col-sm-3 control-label">
                                Phone:
                        </label>
                        <div class="col-sm-9 read-row">
                            <div id="field-vendor_name" class="readonly_label">'.
                                $row->phone.'
                            </div>                            
                        </div>
                    </div>      

                    <div class="form-group row">
                        <label class="col-sm-3 control-label">
                                Vendor Email:
                        </label>
                        <div class="col-sm-9 read-row">
                            <div id="field-vendor_name" class="readonly_label">'.
                                $row->vendor_email.'
                            </div>                            
                        </div>
                    </div>      
                    
                    <div class="form-group row">
                        <label class="col-sm-3 control-label">
                                Reference Person:
                        </label>
                        <div class="col-sm-9 read-row">
                            <div id="field-vendor_name" class="readonly_label">'.
                                $row->salutation.' '.$row->first_name.' '.$row->last_name.'
                            </div>                            
                        </div>
                    </div>
                    
                    <div class="form-group row">
                        <label class="col-sm-3 control-label">
                                Reference Person Gender:
                        </label>
                        <div class="col-sm-9 read-row">
                            <div id="field-vendor_name" class="readonly_label">'.
                                $row->gender.'
                            </div>                            
                        </div>
                    </div>      
                    
                    <div class="form-group row">
                        <label class="col-sm-3 control-label">
                                Reference Person Email:
                        </label>
                        <div class="col-sm-9 read-row">
                            <div id="field-vendor_name" class="readonly_label">'.
                                $row->email_address.'
                            </div>                            
                        </div>
                    </div>  
                    
                    <div class="form-group row">
                        <label class="col-sm-3 control-label">
                                Reference Person Office Phone Number:
                        </label>
                        <div class="col-sm-9 read-row">
                            <div id="field-vendor_name" class="readonly_label">'.
                                $row->work_tel_number.'
                            </div>                            
                        </div>
                    </div>     
                    
                    <div class="form-group row">
                        <label class="col-sm-3 control-label">
                                Reference Person Mobile Phone Number:
                        </label>
                        <div class="col-sm-9 read-row">
                            <div id="field-vendor_name" class="readonly_label">'.
                                $row->mobile_number.'
                            </div>                            
                        </div>
                    </div>         
                
                </div>
                <br>';
        }
                                                                               
        return $officies_locations_list; // '<a href="'.$value.'" target="_blank">'.$value.'</a>';
    
    }

Any ideas? Anyway that functions are not reported in the documentation still after 5 years, could anyone udpate?