简体   繁体   English

杂货店回调

[英]grocery crud call back

I'm Having an issue understanding and using the Grocery crud callback funtion...the documentation isn't clear. 我有一个问题理解和使用Grocery crud回调功能...文档不清楚。

I have 3 tables: 我有3张桌子:
1. Team $crud->fields('TeamID','Name', 'HomeCountry'); 1. 团队 $ crud-> fields('TeamID','Name','HomeCountry');
2. Player $crud->fields('PlayerID','Fname', 'Sname', Title', 'Role','TeamID'); 2. 玩家 $ crud-> fields('PlayerID','Fname','Sname',Title','Role','TeamID'); TeamID = FK to Team TeamID = FK到团队
3. ID card $crud->fields('PlayerID', 'StartDate', 'EndDate', 'statusID'); 3. 身份证 $ crud-> fields('PlayerID','StartDate','EndDate','statusID'); PlayerID = FK to player PlayerID =玩家的FK

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. 在卡片的主要crud列表页面上,我想要做的是显示每个ID卡链接的团队,但团队和ID没有直接设置关系。

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. 我希望从团队中获取所有信息并提取并显示与有问题的卡相关的团队名称,该卡通过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 ) 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 . 对于此回调, return value是必需的,并且必须是字符串

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 假设您有一些字段说timestamp其表中的值为1490295400并且您希望将其显示为03/24/2017 00:26:40 ,而不是在表中更改,您将调用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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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