Files
ulthon_information/extend/think/response/Htmx.php
2025-05-05 10:29:49 +08:00

34 lines
600 B
PHP

<?php
namespace think\response;
use think\Response;
class Htmx extends Response
{
protected $triggerOptions = [];
public function addTrigger($name, $data = null)
{
$this->triggerOptions[$name] = $data;
return $this;
}
public function message($message)
{
$this->triggerOptions['layerMsg'] = ['type' => 1, 'title' => $message];
return $this;
}
protected function output($data)
{
$this->header([
'HX-Trigger' => json_encode($this->triggerOptions),
]);
return parent::output($data);
}
}