Commit d6ec5d6d authored by guilhermeblanco's avatar guilhermeblanco

Small cosmetics in pagination chapter (0.10 and trunk)

parent 1ab785ac
...@@ -25,18 +25,18 @@ Now we know how to create the {{Doctrine_Pager_Layout}} and the types that are a ...@@ -25,18 +25,18 @@ Now we know how to create the {{Doctrine_Pager_Layout}} and the types that are a
<code type="php"> <code type="php">
// Creating pager layout // Creating pager layout
$pager_layout = new Doctrine_Pager_Layout( $pager_layout = new Doctrine_Pager_Layout(
new Doctrine_Pager( new Doctrine_Pager(
Doctrine_Query::create() Doctrine_Query::create()
->from( 'User u' ) ->from( 'User u' )
->leftJoin( 'u.Group g' ) ->leftJoin( 'u.Group g' )
->orderby( 'u.username ASC' ), ->orderby( 'u.username ASC' ),
$currentPage, $currentPage,
$resultsPerPage $resultsPerPage
), ),
new Doctrine_Pager_Range_Sliding(array( new Doctrine_Pager_Range_Sliding(array(
'chunk' => 5 'chunk' => 5
)), )),
'http://wwww.domain.com/app/User/list/page,{%page_number}' 'http://wwww.domain.com/app/User/list/page,{%page_number}'
); );
// Assigning templates for page links creation // 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 ...@@ -63,19 +63,19 @@ The first change we need to do is tho adjust the {{Doctrine_Query}} object and a
<code type="php"> <code type="php">
// Creating pager layout // Creating pager layout
$pager_layout = new Doctrine_Pager_Layout( $pager_layout = new Doctrine_Pager_Layout(
new Doctrine_Pager( new Doctrine_Pager(
Doctrine_Query::create() Doctrine_Query::create()
->from( 'User u' ) ->from( 'User u' )
->leftJoin( 'u.Group g' ) ->leftJoin( 'u.Group g' )
->where( 'LOWER(u.username) LIKE LOWER(?)', array( '%'.$_GET['search'].'%' ) ) ->where( 'LOWER(u.username) LIKE LOWER(?)', array( '%'.$_GET['search'].'%' ) )
->orderby( 'u.username ASC' ), ->orderby( 'u.username ASC' ),
$currentPage, $currentPage,
$resultsPerPage $resultsPerPage
), ),
new Doctrine_Pager_Range_Sliding(array( new Doctrine_Pager_Range_Sliding(array(
'chunk' => 5 'chunk' => 5
)), )),
'http://wwww.domain.com/app/User/list/page,{%page_number}?search={%search}' 'http://wwww.domain.com/app/User/list/page,{%page_number}?search={%search}'
); );
</code> </code>
...@@ -89,6 +89,10 @@ $pager_layout->setSelectedTemplate('[{%page}]'); ...@@ -89,6 +89,10 @@ $pager_layout->setSelectedTemplate('[{%page}]');
// Fetching users // Fetching users
$users = $pager_layout->execute(); $users = $pager_layout->execute();
foreach ($users as $user) {
// ...
}
</code> </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. 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 ...@@ -98,7 +102,7 @@ Custom masks are defined in key => value pairs. So all needed code is to define
<code type="php"> <code type="php">
// Displaying page links // Displaying page links
$pager_layout->display( array( $pager_layout->display( array(
'search' => urlencode($_GET['search']) 'search' => urlencode($_GET['search'])
) ); ) );
</code> </code>
......
...@@ -41,10 +41,10 @@ Now that we know how the different of styles of pager range works, it's time to ...@@ -41,10 +41,10 @@ Now that we know how the different of styles of pager range works, it's time to
<code type="php"> <code type="php">
$pager_range = new Doctrine_Pager_Range_Sliding( $pager_range = new Doctrine_Pager_Range_Sliding(
array( array(
'chunk' => 5 // Chunk length 'chunk' => 5 // Chunk length
), ),
$pager // Doctrine_Pager object we learned how to create in previous topic $pager // Doctrine_Pager object we learned how to create in previous topic
); );
</code> </code>
......
...@@ -7,12 +7,12 @@ $resultsPerPage = 50; ...@@ -7,12 +7,12 @@ $resultsPerPage = 50;
// Creating pager object // Creating pager object
$pager = new Doctrine_Pager( $pager = new Doctrine_Pager(
Doctrine_Query::create() Doctrine_Query::create()
->from( 'User u' ) ->from( 'User u' )
->leftJoin( 'u.Group g' ) ->leftJoin( 'u.Group g' )
->orderby( 'u.username ASC' ), ->orderby( 'u.username ASC' ),
$currentPage, // Current page of request $currentPage, // Current page of request
$resultsPerPage // (Optional) Number of results per page. Default is 25 $resultsPerPage // (Optional) Number of results per page. Default is 25
); );
</code> </code>
...@@ -28,7 +28,11 @@ If you try to access any of the methods provided by Doctrine_Pager now, you'll e ...@@ -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: 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"> <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> </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: 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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment