开发者

passing optional variable to pagination in codeigniter

What I would really like to do is create an optional text to pass to a controller method in codeigniter.

Currently I have something like this

public function manage($page = 1, $method = '', $id=0)
{
    //code
}

So if the parameters are not passed the pagination displays normally, and if they are then some variables are set in the view to give some feedb开发者_如何学Pythonack to the user.

However I get this error when I try it out:

http://domain.path/to/controller/method/1/test/1

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1', 50' at line 5

SELECT CONCAT('so_',id,'_am'), value, updated, FROM words LIMIT '1', 50

So it seems to be that the segment is being cast as a string for some reason, and this is causing the error.

Any ideas on how to work around this constraint?


it looks like your query builder automatically adds quotes around strings. cast $page as int explicitly.

$page = "4";
$offset = "4";
$qb->setLimit((int)$page,(int)$offset)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜