PHP code example of zyan / thinkphp3-sitemap
1. Go to this page and download the library: Download zyan/thinkphp3-sitemap library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zyan / thinkphp3-sitemap example snippets
use Zyan\Sitemap\Sitemap;
//根地址
$baseUrl = 'http://www.php127.com/';
$sitemap = Factory::tp3Sitemap($baseUrl);
$sitemap->table('表名')->where(['where条件 可不传'])->field(['字段'])->url('url规则')->make();
//可生成多个表
$sitemap->table('表名')->url('url规则')->make();
//不需要填写前缀
$sitemap->table('article')->make();
//请参考tp3手册中where传数组的方法
$sitemap->table('article')->where([['id','>',1000],['state','=',1]])->make();
//请参考tp3手册field传的方法 注意这里转换成数组
$sitemap->table('article')->field(['id','...'])->make();
//配合field字段为变量替换url 请用{}括起来
$sitemap->table('article')->field(['id'])->url('/article/{uid}.html')->make();
//可以有多个
$sitemap->table('article')->field(['id','type'])->url('/article/{type}/{uid}.html')->make();
//也可以指定域名 不指定默认以 读取 config('app.url')
$sitemap->table('article')->field(['id','type'])->url('http://www.php127.com/article/{id}.html')->make();
//开始生成
$sitemap->table('article')->field(['id'])->url('/user/{id}.html')->make();