Typecho——Argument 1 passed to Typecho\Router::get() must be of the type string

简介: Typecho——Argument 1 passed to Typecho\Router::get() must be of the type string

前言

开发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);
}

学无止境,谦卑而行.

目录
相关文章
|
前端开发 Java 数据库连接
Spring Boot 升级 3.2 报错 Invalid value type for attribute ‘factoryBeanObjectType‘: java.lang.String
Spring Boot 升级 3.2 报错 Invalid value type for attribute ‘factoryBeanObjectType‘: java.lang.String
|
8月前
|
SQL 数据库
【YashanDB 知识库】导入数据时报错:YAS-00008 type convert error:literal does not match format string
【YashanDB 知识库】导入数据时报错:YAS-00008 type convert error:literal does not match format string
|
8月前
|
SQL 数据库
【YashanDB知识库】导入数据时报错:YAS-00008 type convert error:literal does not match format string
【YashanDB知识库】导入数据时报错:YAS-00008 type convert error:literal does not match format string
解决Missing cookie ‘JssionId‘ for method parameter of type String问题
解决Missing cookie ‘JssionId‘ for method parameter of type String问题
304 0
Excel上传出错:TypeError [ERR_INVALID_ARG_TYPE]: The “path“ argument must be of type string or an instan
Excel上传出错:TypeError [ERR_INVALID_ARG_TYPE]: The “path“ argument must be of type string or an instan
|
Python
TypeError: int() argument must be a string, a bytes原因
Python开发过程中,使用int()函数来转换或生成int类型的数据时,如果Python抛出并提示TypeError: int() argument must be a string, a bytes-like object or a real number, not 'complex',那么原因在于传递给int()函数的参数类型有误,正如TypeError的提示,int()函数的参数必须是string字符串(数值字符串)、类似字节对象、real number数字等,而不可以是complex复数类型的数据。
851 0
|
人工智能 自然语言处理 语音技术
Invalid prop: type check failed for prop “index“. Expected String with value “5“问题解决
Invalid prop: type check failed for prop “index“. Expected String with value “5“问题解决
427 0
|
XML 数据格式
解决 Cannot convert value of type ‘java.lang.String‘ to required type ‘java.sql.Driver‘ for property ‘
解决 Cannot convert value of type ‘java.lang.String‘ to required type ‘java.sql.Driver‘ for property ‘
627 0
|
1月前
|
编解码 Java 开发者
Java String类的关键方法总结
以上总结了Java `String` 类最常见和重要功能性方法。每种操作都对应着日常编程任务,并且理解每种操作如何影响及处理 `Strings` 对于任何使用 Java 的开发者来说都至关重要。
239 5
|
5月前
|
存储 编译器 C语言
关于string的‘\0‘与string,vector构造特点,反迭代器与迭代器类等的讨论
你真的了解string的'\0'么?你知道创建一个string a("abcddddddddddddddddddddddddd", 16);这样的string对象要创建多少个对象么?你知道string与vector进行扩容时进行了怎么的操作么?你知道怎么求Vector 最大 最小值 索引 位置么?
137 0