1
0
mirror of synced 2024-12-13 22:56:04 +03:00

Small cosmetics in pagination chapter (0.10 and trunk)

This commit is contained in:
guilhermeblanco 2008-02-21 04:40:00 +00:00
parent 1ab785ac44
commit d6ec5d6df2
3 changed files with 45 additions and 37 deletions

View File

@ -25,18 +25,18 @@ Now we know how to create the {{Doctrine_Pager_Layout}} and the types that are a
<code type="php">
// Creating pager layout
$pager_layout = new Doctrine_Pager_Layout(
new Doctrine_Pager(
Doctrine_Query::create()
->from( 'User u' )
->leftJoin( 'u.Group g' )
->orderby( 'u.username ASC' ),
$currentPage,
$resultsPerPage
),
new Doctrine_Pager_Range_Sliding(array(
'chunk' => 5
)),
'http://wwww.domain.com/app/User/list/page,{%page_number}'
new Doctrine_Pager(
Doctrine_Query::create()
->from( 'User u' )
->leftJoin( 'u.Group g' )
->orderby( 'u.username ASC' ),
$currentPage,
$resultsPerPage
),
new Doctrine_Pager_Range_Sliding(array(
'chunk' => 5
)),
'http://wwww.domain.com/app/User/list/page,{%page_number}'
);
// Assigning templates for page links creation
@ -63,19 +63,19 @@ The first change we need to do is tho adjust the {{Doctrine_Query}} object and a
<code type="php">
// Creating pager layout
$pager_layout = new Doctrine_Pager_Layout(
new Doctrine_Pager(
Doctrine_Query::create()
->from( 'User u' )
->leftJoin( 'u.Group g' )
->where( 'LOWER(u.username) LIKE LOWER(?)', array( '%'.$_GET['search'].'%' ) )
->orderby( 'u.username ASC' ),
$currentPage,
$resultsPerPage
),
new Doctrine_Pager_Range_Sliding(array(
'chunk' => 5
)),
'http://wwww.domain.com/app/User/list/page,{%page_number}?search={%search}'
new Doctrine_Pager(
Doctrine_Query::create()
->from( 'User u' )
->leftJoin( 'u.Group g' )
->where( 'LOWER(u.username) LIKE LOWER(?)', array( '%'.$_GET['search'].'%' ) )
->orderby( 'u.username ASC' ),
$currentPage,
$resultsPerPage
),
new Doctrine_Pager_Range_Sliding(array(
'chunk' => 5
)),
'http://wwww.domain.com/app/User/list/page,{%page_number}?search={%search}'
);
</code>
@ -89,6 +89,10 @@ $pager_layout->setSelectedTemplate('[{%page}]');
// Fetching users
$users = $pager_layout->execute();
foreach ($users as $user) {
// ...
}
</code>
The method {{display()}} is the place where we define the custom mask we created. This method accepts 2 optional arguments: one array of optional masks and if the output should be returned instead of printed on screen.
@ -98,7 +102,7 @@ Custom masks are defined in key => value pairs. So all needed code is to define
<code type="php">
// Displaying page links
$pager_layout->display( array(
'search' => urlencode($_GET['search'])
'search' => urlencode($_GET['search'])
) );
</code>

View File

@ -41,10 +41,10 @@ Now that we know how the different of styles of pager range works, it's time to
<code type="php">
$pager_range = new Doctrine_Pager_Range_Sliding(
array(
'chunk' => 5 // Chunk length
),
$pager // Doctrine_Pager object we learned how to create in previous topic
array(
'chunk' => 5 // Chunk length
),
$pager // Doctrine_Pager object we learned how to create in previous topic
);
</code>

View File

@ -7,12 +7,12 @@ $resultsPerPage = 50;
// Creating pager object
$pager = new Doctrine_Pager(
Doctrine_Query::create()
->from( 'User u' )
->leftJoin( 'u.Group g' )
->orderby( 'u.username ASC' ),
$currentPage, // Current page of request
$resultsPerPage // (Optional) Number of results per page. Default is 25
Doctrine_Query::create()
->from( 'User u' )
->leftJoin( 'u.Group g' )
->orderby( 'u.username ASC' ),
$currentPage, // Current page of request
$resultsPerPage // (Optional) Number of results per page. Default is 25
);
</code>
@ -28,7 +28,11 @@ If you try to access any of the methods provided by Doctrine_Pager now, you'll e
To run the query, the process is similar to the current existent {{Doctrine_Query}} execute call. It even allow arguments the way you usually do it. Here is the PHP complete syntax, including the syntax of optional parameters:
<code type="php">
$pager->execute([$args = array() [, $fetchType = Doctrine::FETCH_RECORD]]);
$items = $pager->execute([$args = array() [, $fetchType = Doctrine::FETCH_RECORD]]);
foreach ($items as $item) {
// ...
}
</code>
There are some special cases where the return records query differ of the counter query. To allow this situation, {{Doctrine_Pager}} has some methods that enable you to count and then to execute. The first thing you have to do is to define the count query: