public function xml()
{
$request = Request::instance();
$url = $request->domain();//获取当前请求域名
$res = Db::name('data')->order('id desc')->select();
$html = '';
$html .= '<urlset>';
foreach ($res as $key => $value) {
$create_time=date('Y-m-s',$value['create_time']);
$html .= '<url>';
$html .= '<loc>'.$url.'/'. $value['id'] . '.html</loc>';
$html .= ' <lastmod>' . $create_time. '</lastmod>';
$html .= ' <changefreq>Always</changefreq>';
$html .= ' <priority>0.8</priority>';
$html .= '</url>';
}
$html .= '</urlset>';
return xml([$html,200,[],['root_node'=>'xml']]);
}
网友评论