File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,7 +19,8 @@ class Pager extends BaseConfig
1919 */
2020 public $ templates = [
2121 'default_full ' => 'CodeIgniter\Pager\Views\default_full ' ,
22- 'default_simple ' => 'CodeIgniter\Pager\Views\default_simple '
22+ 'default_simple ' => 'CodeIgniter\Pager\Views\default_simple ' ,
23+ 'default_header ' => 'CodeIgniter\Pager\Views\default_header '
2324 ];
2425
2526 /*
Original file line number Diff line number Diff line change 4545 */
4646class RedirectException extends \Exception
4747{
48-
48+
4949}
5050
5151/**
@@ -343,6 +343,23 @@ public function setDate(\DateTime $date)
343343
344344 //--------------------------------------------------------------------
345345
346+ /**
347+ * Set the Link Header
348+ *
349+ * @param \CodeIgniter\Pager\Pager $pager
350+ *
351+ * @return Response
352+ */
353+ public function setLink (Pager $ pager )
354+ {
355+ // http://tools.ietf.org/html/rfc5988
356+ $ this ->setHeader ('Link ' , $ pager ->links ('default ' , 'default_header ' ));
357+
358+ return $ this ;
359+ }
360+
361+ //--------------------------------------------------------------------
362+
346363 /**
347364 * Sets the Content Type header for this response with the mime type
348365 * and, optionally, the charset.
Original file line number Diff line number Diff line change 1+ <?php
2+ $ pager ->setSurroundCount (0 );
3+ $ links = '' ;
4+ if ($ pager ->hasPrevious ())
5+ {
6+ $ links .= '< ' . $ pager ->getFirst () . '>; rel="first", ' ;
7+ $ links .= '< ' . $ pager ->getPrevious () . '>; rel="prev" ' ;
8+ }
9+ if ($ pager ->hasPrevious () && $ pager ->hasNext ())
10+ {
11+ $ links .= ', ' ;
12+ }
13+ if ($ pager ->hasNext ())
14+ {
15+ $ links .= '< ' . $ pager ->getNext () . '>; rel="next", ' ;
16+ $ links .= '< ' . $ pager ->getLast () . '>; rel="last" ' ;
17+ }
18+ echo $ links ;
You can’t perform that action at this time.
0 commit comments