gpt4 book ai didi

php - Cakephp 显示其中 1=1

转载 作者:行者123 更新时间:2023-11-29 22:24:53 24 4
gpt4 key购买 nike

您好,我正在创建简单的博客网站,在登陆页面查看博客,但如果用户选择任何类别,则仅列出此类别下的博客。我的问题是,当用户从右侧边栏中选择类别时,它会返回所有表记录。当我打印查询时,它返回:

array(
'log' => array(
(int) 0 => array(
'query' => 'SELECT `Category`.`category_id`, `Category`.`name` FROM `cakeBlog`.`categories` AS `Category` WHERE 1 = 1',
'params' => array(),
'affected' => (int) 13,
'numRows' => (int) 13,
'took' => (float) 0
),
(int) 1 => array(
'query' => 'SELECT `Post`.`id`, `Post`.`category_id`, `Post`.`title`, `Post`.`body`, `Post`.`created`, `Post`.`modified`, `Post`.`user_id` FROM `cakeBlog`.`posts` AS `Post` WHERE 1 = 1 LIMIT 20',
'params' => array(),
'affected' => (int) 13,
'numRows' => (int) 13,
'took' => (float) 0
)
),
'count' => (int) 2,
'time' => (float) 0
)

这是我的 Controller 文件 PostsController.php

在索引函数中我将检查类别ID是否存在?

请帮帮我...谢谢

最佳答案

使用以下 block 来获取类别

if(is_null($categoryId)) {
$this->Paginator->setting = array(
'limit' =>'10',
'order' => array('Post.id' =>'Desc')
/*'conditions' => array(
'Post.user_id' => AuthComponent::user(id)
)*/
);
$arrPosts = $this->Paginator->paginate('Post');
$this->set('posts', $arrPosts);
} else {
$condition = array('Post.category_id' => $categoryId,'limit' =>'10');
$da = $this->Paginator->setting = array(
'conditions' => $condition
/*'conditions' => array(
'Post.user_id' => AuthComponent::user(id)
)*/
);

$arrPosts = $this->Paginator->paginate('Post');
$log = $this->Post->getDataSource()->getLog(false, false); debug($log);
$this->set('posts', $arrPosts);
}

关于php - Cakephp 显示其中 1=1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30365201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com