⚠ 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

How to change fields values on the list and read



Evandro

Evandro
  • profile picture
  • Member

Posted 23 June 2014 - 12:28 PM

Can someone help me please ?

 

if ($crud->columns['NAME'] == '')
{
    $crud->columns['NAME'] = "Anonymous";
}

 

How can I do it the right way ?


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 25 June 2014 - 03:19 AM

Well this is a call for callback_column function where you can change the value that is to be displayed for the column

and in case of read you can refer to solution provided on the following url

/topic/2525-callback-addedit-field-changes-the-display-on-the-read-method/

 

Happy GCing :)


Evandro

Evandro
  • profile picture
  • Member

Posted 02 July 2014 - 20:46 PM

Well this is a call for callback_column function where you can change the value that is to be displayed for the column

and in case of read you can refer to solution provided on the following url

/topic/2525-callback-addedit-field-changes-the-display-on-the-read-method/

 

Happy GCing :)

 

wow, thanks a lot !

 

Just one more question.

 

How can I remove the entire row on read if the field is empty or null ?

 

Like this:

 

if ($crud->columns['NAME'] != '')
{
    // write <div class="form-field-box" id="..."><div class="form-display-as-box" id="...">....

}

else

{

    // remove/do nothing

}


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 03 July 2014 - 05:27 AM

entire row.. meaning the field lable and value .. if empty..

in that case what you can do the following :

1 - Check if the state is read

2 - Retrieve the primary key from the url

3 - Retrieve the row from the table..

4 - Create an array of fields that you want the read function to display based on the logics you need to proceed with.

5 - Set the array to $crud->read_fields()

that should do the trick.

 

Happy Gcing :)


Evandro

Evandro
  • profile picture
  • Member

Posted 14 July 2014 - 18:29 PM

entire row.. meaning the field lable and value .. if empty..

in that case what you can do the following :

1 - Check if the state is read

2 - Retrieve the primary key from the url

3 - Retrieve the row from the table..

4 - Create an array of fields that you want the read function to display based on the logics you need to proceed with.

5 - Set the array to $crud->read_fields()

that should do the trick.

 

Happy Gcing :)


Evandro

Evandro
  • profile picture
  • Member

Posted 14 July 2014 - 18:32 PM

It works! (I'm not sure if it's the best option)
 
if( $crud->getState() == 'read' ){
    $id = substr( current_url(), strrpos( current_url(), '/' )+1 );
    $readFields = $this->callback_getFields($id);
    $crud->fields($readFields);
}


public function callback_getFields($pk = null){
    $ret = array();

    $sql = "SELECT * FROM table WHERE ID = '{$pk}';";

    $query = $this->db->query($sql);

    foreach( $query->result() as $row ){
        foreach( $row as $field => $value ) {
            if( trim($value) != '' && $value != '0'  && $field != 'ID' ){
                $ret[] = $field;
            }
        }
    }
    return $ret;
}
Thank you !