简体   繁体   中英

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 feedback 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM