cakephp 3分页器不起作用 [英] cakephp 3 paginator doesn't work
问题描述
我目前正在CakePHP 3中使用此查询作为一个小型搜索引擎
I'm curently using this query with Cakephp 3 for a little search engine
$query_tweet = $this->Tweet
->find()
->select([
'Users.username',
'Users.avatarprofil',
'Tweet.contenu_tweet',
'Tweet.created',
'Tweet.nb_commentaire',
'Tweet.nb_partage',
'Tweet.nb_like',
])
->where([
"MATCH(Tweet.contenu_tweet) AGAINST(:search)"
])
->where(['private' => 0]) // on ne cherche que les tweets publics
->bind(':search', '$search')
->order(['Tweet.created' => 'DESC'])
->contain(['Users']);
此查询工作正常,但我想使用分页器
This query works perfectly but i want to use the paginator like this
$this->set('resultat_tweet', $this->Paginator->paginate($query_tweet, ['limit' => 8]));
我明白了
错误:SQLSTATE [HY093]:无效的参数编号:绑定变量的数量与令牌的数量不匹配
Error: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
如果将SQL关键字用作表列名,则可以在config/app.php中为数据库连接启用标识符引用.
If you are using SQL keywords as table column names, you can enable identifier quoting for your database connection in config/app.php.
SQL查询:
SELECT
Users.username AS `Users__username`,
Users.avatarprofil AS `Users__avatarprofil`,
Tweet.contenu_tweet AS `Tweet__contenu_tweet`,
Tweet.created AS `Tweet__created`,
Tweet.nb_commentaire AS `Tweet__nb_commentaire`,
Tweet.nb_partage AS `Tweet__nb_partage`,
Tweet.nb_like AS `Tweet__nb_like`
FROM
tweet Tweet
LEFT JOIN
users Users ON Users.username = (Tweet.user_id)
WHERE (
MATCH(Tweet.contenu_tweet) AGAINST(:search)
AND private = :c0
)
ORDER BY
Tweet.created DESC
LIMIT
8 OFFSET 0
我在PHPmyadmin中尝试了此查询,并且可以正常工作,我进行了很多测试以查看是否可以搜索到
i tried this query in PHPmyadmin and it works, i have many tests to see if i get the search and i have it
我真的不知道出了什么问题,我在其他页面上使用了Paginator,并且可以正常工作
i really dont know what's the problem , i 'm using the Paginator on others pages and it work
推荐答案
最后,我通过创建一条新路线来获得想要的东西,我不再使用str_replace
finnaly, i get what i want by creating a new route, i don't use anymore str_replace
最终代码
<?= $this->Paginator->options([
'url' => ['-'.$search.'']
]);
echo $this->Paginator->next('Next page'); ?>
和新路线
Router::connect('/search/index/-:string',['controller' => 'Search', 'action' => 'index']);
非常感谢所有帮助过我的人,尤其是Mathew Foscarini
Thanks a lot to everyone who helped me , especially Mathew Foscarini
这篇关于cakephp 3分页器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!