public static function create($title, $content, $label_ids){
self::$db->action(function($db){
$db->insert('articles', [
'title' => $title,
'content' => $content,
'created_at' => self::$t,
'updated_at' => self::$t,
'created_date' => self::$t_date,
'updated_date' => self::$t_date,
]);
$article_id = $db->id();
$data = [];
foreach(explode(',', $label_ids) as $id){
$data[] = [
'article_id' => $article_id,
'label_id' => $id,
'created_at' => self::$t,
'updated_at' => self::$t,
'created_date' => self::$t_date,
'updated_date' => self::$t_date,
];
}
$db->insert('article_labels', $data);
});
}
如何将action外的变量传递进去
function (...) use (...) {...}
参考 PHP 文档:https://secure.php.net/manual...