Software Woes

Rants, tips and tricks



Thursday, August 06, 2009



CodeIgniter pagination

CI has a nice pagination class, which works nice, but has many shortcomings. It has not been designed with much flexibility in mind, so you might need to roll pagination on your own in the end. What are the problems?

Let's start with a minor one: when you have 4 pages, you get:

first(1) prev(1) 2 3 last(4)

Same link repeats twice. Similar when you navigate to 4th page in the same example.

Then, there's a problem that you cannot turn some of the "components" off. For example, I don't need PREV and NEXT, just first/last and a few pages in the middle (number of those is also NOT configurable, BTW). If you don't set array members in initialize function, it uses defaul values. Default values for start and end tags are not what the docs say, and some defaults are next to useless like

It would be much better if unset stuff defaults to DO NOT DISPLAY.

The interface for pagination class was desined by some narrow minded developer who only knows one way to do pagination. For example, I do not like pure text links, but would like to use nice rectangles. I managed to get something useful with SPANs and custom CSS rules, however, I had to do some workarounds. For example, all the links use simple and clean A tag without any interface to it. So, in order to have links of different color than rest of the links on the page, one has to add some CSS class to the outer element (create a span that floats to left, for example), and then define CSS rule:

'num_tag_open' => '',
'num_tag_close' => '
',

CSS:

.pagg a { color: #fcc }

Need to define all properties to make things look right on the screen is a real PITA.

Another problem is that it only supports determinate sets. I'd like to be able to have pagination without knowing the end record count. The reason for this is that many DBMS don't perform well with SELECT COUNT(*) FROM table1 WHERE some_complex_query.

So, I just fetch initial 100-200 records and display them, showing the users that there is "more" with a link to "next" or "next 5 pages". Of course, this would mean that there is no "last" link, which brings us back to the issue that this class only solves a narrow set of problems.

After completing a first real-world project with it, I get the impression that base stuff in CI is ok, but it hasn't been tested enough in the real world situations. Many features seem to be designed more as a proof of concept than flexible framework designed for real world usage. Poor desing is also shown in Unit Testing which seems to be there just to fill the checkbox in the feature list, and also in ActiveRecord implementation which goes into sillyness of where_not, or_where and whatnot. As if writing select('column1')->from('table1')->where_in('id'=>array(10,20)) is much clearer or flexible than get_where('select column1 from table1 where id in (?)', array(10,20)). IMHO, ActiveRecord should stay on the CRUD level.

1 Comments:

At 5:56 AM, Anonymous Webtronica said...

to say that CI has "a nice pagination class" is being too nice. The fact it doesn't work with your query is a major drawback for me. But beyond that purely as a pagination helper for the view (and you don't even use it in the view much if any), it has no flexibility.

It was nice to read an article that agreed with me on how horrible CI's pagination is. The pagination is a horrible drawback to this framework, I'm almost terrified to even look into sorting.

I feel CI is the worst php framework. CakePHP and Yii have been SOOOO much nicer and easier to use.

 

Post a Comment

<< Home