前言
开发EasyBe
主题的置顶功能时候,测试的时候出现了Typecho\Router::get()
报错,根据对应的报错信息查看了下源码后解决了该问题;
内容
查询SQL
// 获取全部文章
function getAllPosts($page, $limit) {
$db = Typecho_Db::get();
$sql = $db->select('c.cid', 'c.title', 'c.created', 'c.text', 'c.password', 'c.commentsNum', 'c.views', 'c.digg', 'f.str_value as sticky')
->from('table.contents as c')
->join('table.fields as f', 'f.cid = c.cid', Typecho_Db::LEFT_JOIN)
->where('c.status = ? and c.type = ?', 'publish', 'post')
->order('sticky', Typecho_Db::SORT_DESC)
->order('c.created', Typecho_Db::SORT_DESC)
->page($page, $limit);
return $db->fetchAll($sql);
}
报错信息
根据报错,这里我们只需要关注#0的提示即可;
Argument 1 passed to Typecho\Router::get() must be of the type string, null given, called in /data/wwwroot/dev.wangyangyang.vip/build/var/Widget/Base/Contents.php on line 536
TypeError: Argument 1 passed to Typecho\Router::get() must be of the type string, null given, called in /data/wwwroot/dev.wangyangyang.vip/build/var/Widget/Base/Contents.php on line 536 and defined in /data/wwwroot/dev.wangyangyang.vip/build/var/Typecho/Router.php:170
Stack trace:
#0 /data/wwwroot/dev.wangyangyang.vip/build/var/Widget/Base/Contents.php(536): Typecho\Router::get(NULL)
#1 /data/wwwroot/dev.wangyangyang.vip/build/var/Widget/Base/Contents.php(478): Widget\Base\Contents->filter(Array)
#2 /data/wwwroot/dev.wangyangyang.vip/build/usr/themes/easybe/index.php(19): Widget\Base\Contents->push(Array)
#3 /data/wwwroot/dev.wangyangyang.vip/build/var/Widget/Archive.php(1415): require_once('/data/wwwroot/d...')
#4 /data/wwwroot/dev.wangyangyang.vip/build/var/Typecho/Router.php(99): Widget\Archive->render()
#5 /data/wwwroot/dev.wangyangyang.vip/build/index.php(23): Typecho\Router::dispatch()
#6 {main}
排查经过
根据报错进入到对应的文件中,使用
vi
进行编辑;
?> 到这里其实问题已经就解决了,因为我上面查询的SQL中,并没有将字段type
筛选出来,所以这里才导致了传NULL的情况;
解决
把~c c.type c~加入查询字段即可;
// 获取全部文章
function getAllPosts($page, $limit) {
$db = Typecho_Db::get();
$sql = $db->select('c.cid', 'c.title', 'c.created', 'c.text', 'c.password', 'c.commentsNum', 'c.views', 'c.type', 'c.digg', 'f.str_value as sticky')
->from('table.contents as c')
->join('table.fields as f', 'f.cid = c.cid', Typecho_Db::LEFT_JOIN)
->where('c.status = ? and c.type = ?', 'publish', 'post')
->order('sticky', Typecho_Db::SORT_DESC)
->order('c.created', Typecho_Db::SORT_DESC)
->page($page, $limit);
return $db->fetchAll($sql);
}
标签:wwwroot,string,get,type,dev,vip,Typecho,data
From: https://www.cnblogs.com/wangyang0210/p/17146422.html