Codeigniter 使用pyro插件将变量调用到查询中
我有一个插件,根据表中的数字、公文包类型等获取不同的项目 到目前为止,该类型正在工作,但我无法获得工作的极限偏移量,这是代码点火器Codeigniter 使用pyro插件将变量调用到查询中,codeigniter,pyrocms,Codeigniter,Pyrocms,我有一个插件,根据表中的数字、公文包类型等获取不同的项目 到目前为止,该类型正在工作,但我无法获得工作的极限偏移量,这是代码点火器 $type = $this->attribute('type', ''); $portfolioNum = $this->attribute('portfolioNum', ''); if ($portfolioNum !=0){ $portfolioNum = settype($
$type = $this->attribute('type', '');
$portfolioNum = $this->attribute('portfolioNum', '');
if ($portfolioNum !=0){
$portfolioNum = settype($portfolioNum, "integer");
}
$data = $this->db->select('portfolio.*, artists.artist_name event_title, artists.artist_slug event_slug')
->from('portfolio')
->where('portfolio_type', $type)
->where('portfolio_selected', 'Selected')
->limit(1, 0)
->join('artists_portfolio', 'portfolio.id = artists_portfolio.portfolio_id', 'LEFT')
->join('artists', 'artists.id = artists_portfolio.row_id', 'LEFT')
->get()
->result();
这很好,使用公文包类型获取表中的第一项
当我尝试在中添加变量而不是偏移量0时,它会中断
$type = $this->attribute('type', '');
$portfolioNum = $this->attribute('portfolioNum', '');
if ($portfolioNum !=0){
$portfolioNum = 1;
}
$data = $this->db->select('portfolio.*, artists.artist_name event_title, artists.artist_slug event_slug')
->from('portfolio')
->where('portfolio_type', $type)
->where('portfolio_selected', 'Selected')
->limit(1, $portfolioNum)
->join('artists_portfolio', 'portfolio.id = artists_portfolio.portfolio_id', 'LEFT')
->join('artists', 'artists.id = artists_portfolio.row_id', 'LEFT')
->get()
->result();
并在模板中调用
{{TheSitePlugin:getSelected type="Production" portfolioNum="1"}}{{/TheSitePlugin:getSelected}}
我很确定问题出在这些方面:
if ($portfolioNum !=0){
$portfolioNum = 1;
}
从我看到的情况来看,$portfolioNum从来都不是0,因此将始终设置为0
改变
$portfolioNum = $this->attribute('portfolioNum', '');
到
并删除整个if子句。这样,如果没有将portfolioNum设置为标记属性,插件类的attribute函数将$portfolioNum设置为0
但是您可能仍然需要检查portfolioNum是否是一个整数等等。
als可能会将portfolioNum重命名为“offset”,因为它就是这样。尝试调试您的查询,您可以将
?\u debug
添加到您的URL,同时使用admin user查看包括所有查询在内的大量内容。PyroCMS在调试方面非常好,我不知道你能做到,谢谢$这个->属性('portfolioNum')可以是0或1,但当它是1时,偏移量应该是1,否则偏移量应该是0-如果帮助更改为$offset=0,我可以重命名变量;如果($portfolioNum!=0){$offset=1;}并且效果很好
$portfolioNum = $this->attribute('portfolioNum', 0);