简体   繁体   English

PHP食品杂货 插入多个字段之前的回调

[英]PHP Grocery Crud | Callback Before Insert multple fields

The idea is when I add a new row, one of the field (ID) have to has a default value + Value of another field + date. 我的想法是,当我添加新行时,其中一个字段(ID)必须具有默认值+另一个字段的值+日期。

Example of ID: IDPeter17112017 ID的示例:IDPeter17112017

So, this is the code I have but it doesn't work, or maybe isn't the best way to do it. 因此,这是我拥有的代码,但是它不起作用,或者可能不是最佳方法。

$crud->add_fields('name','email','date');
$crud->callback_before_insert(function ($post_array)  {
$name =  $name['name']; 
$date = $date['date'];

if (empty($post_array['id'])) {
$post_array['id'] = 'ID' . $name . $date;
}

return $post_array;
});

But unfortunetly the name and date does not display... 但不幸的是,名称和日期没有显示。

Any suggestions? 有什么建议么?

Thank in adavance 谢谢

Aboslutely doing it wrong. 绝对做错了。 I need to use "Callback_column" for this. 我需要为此使用“ Callback_column”。

This is what I did and it works like a charm: 这就是我所做的,并且就像一个魅力一样工作:

$crud->add_fields('name','email','date');
$crud->callback_column('id',array($this,'id_callback'));
$output = $crud->render();
function id_callback($value, $row)
{
return "ID" . $row->name . $row->date;
}

:) :)

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

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