简体   繁体   中英

grocery crud call back

I'm Having an issue understanding and using the Grocery crud callback funtion...the documentation isn't clear.

I have 3 tables:
1. Team $crud->fields('TeamID','Name', 'HomeCountry');
2. Player $crud->fields('PlayerID','Fname', 'Sname', Title', 'Role','TeamID'); TeamID = FK to Team
3. ID card $crud->fields('PlayerID', 'StartDate', 'EndDate', 'statusID'); PlayerID = FK to player

On the main crud list page for cards what I want to do is also show what team each ID card is linked with however Team and ID have not direct set relation.

Is this possible with a Callback function? I have the foloowing code format but i dont know what its doing or what each bit of the callback function actually means ???

I want to get all the info from teams and extract and display the team name only that relates to the card in question which is link to a particular player through FK.

    $crud->callback_column('teamID', function(){  
        $query = $this->db->query("SELECT * FROM");  
    $rows = $query->result();  
        $var = $rows[0]->;  
        /*  
        foreach ($rows as $row) {  
            $var = $row->;  
            //$var2 = $row->;  
            //$var3 = $row->;  
        }  
        * */  
        //$this->db->query("INSERT INTO  () VALUES );");  
        return ;  
    });  

Sorry I have no idea how to format code on this page, this whole thing is very fustrating.

        function _add_default_date_value()  //this function adds a text value as     display, date is not stored in database (use post to amend later
    {
        $value = !empty($value) ? $value : date("(d/m/y)");
        $return = '<input type="text" name="date" value="'.$value.'"     class="datepicker-input" /> ';
        $return .= '<a class="datepicker-input-clear" tabindex="-1">Clear</a>     (dd/mm/yyyy)';
        return $return;
    }

callback_column : void callback_column( string $column , mixed $callback )

This callback runs on each row. It escapes the auto column value and runs the callback.

This callback runs on each row. It escapes the auto column value and runs the callback. For this callback the return value is required and must be a string .

So where it useful ?

Suppose you got some field say timestamp whose value in your table is 1490295400 and you want to display it as 03/24/2017 00:26:40 , instead of changing in your table, you will call callback_column

/* This is your crud method */
function my_crud()
{
  $crud = new grocery_CRUD();
  ...
  ...
  $crud->callback_column(
           'timestamp',
           array($this,'_callback_convert_to_human_readable')
  );
  ...
  ...

}

/* So this is your callback */
function _callback_convert_to_human_readable($value, $row)
{
     return date("m/d/Y H:i:s", $value);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM