Repository: codeigniter4/CodeIgniter4 (PHP)

Issue:
Bug: Can't use multiple pagers on the same view
### PHP Version

8.0

### CodeIgniter4 Version

4.1.2

### CodeIgniter4 Installation Method

Composer (as dependency to an existing project)

### Which operating systems have you tested for this bug?

Linux

### Which server did you use?

apache

### Database

MariaDB 10.6.5

### What happened?

Can't use multiple pagers on the same view. I followed docs from [here](https://codeigniter.com/user_guide/libraries/pagination.html?highlight=pagination#id3).

### Steps to Reproduce

Here is my simplified Controller function:

```php
public function view(int $clientId)
{
      $contacts = $this->getContactProvider();
      $orders   = $this->getOrderProvider();
      
      return view($this->viewPrefix . 'view', [
                  'title'      => lang('Client.client'),
                  'contacts'   => $contacts->whereClient($clientId)->paginate(preference('Pager.perPage'), 'contacts'),
                  'orders'     => $orders->whereClient($clientId)->paginate(preference('Pager.perPage'), 'orders'),
                  'pager'      => $contacts->whereClient($clientId)->pager,
              ]);
}
```

### Expected Output

Get two groups in Pager instance and show pagers in view with 

```php
<?= $pager->simpleLinks('contacts') ?>
<?= $pager->links('orders') ?>
```

but there is only one group
![CleanShot 2022-06-29 at 15 34 27@2x](https://user-images.githubusercontent.com/36922215/176449713-43914d3b-7913-4a20-bf49-6861afb0bfce.png)



### Anything else?

Within view I can show two paginations, but can access only that one where I'm calling `pager` method.
![CleanShot 2022-06-29 at 15 41 25@2x](https://user-images.githubusercontent.com/36922215/176451400-26379e75-28e2-4434-bdb4-63dc5d755644.png)

But when I manually specify `page_contacts` like:

```
?page_contacts=2&page_orders=1
```

It will show previous page in pagination

![CleanShot 2022-06-29 at 15 44 38@2x](https://user-images.githubusercontent.com/36922215/176451926-bdf2f385-edac-4ee1-be86-a5bc8239bc27.png)

I'm expecting both paginations the same, because there is two pages for both of results. 


Discussion:
It seems like an issue with ignoring provided `perPage` parameter within second group. 

Here is the result of:

```php
<?= dd($pager) ?>
```

in view

![CleanShot 2022-06-29 at 16 55 37@2x](https://user-images.githubusercontent.com/36922215/176469124-0cd97cb2-5fd0-4d7f-86a4-147d6fe116ad.png)

it's using default config value. It's the same if I use integer like:

```php
'orders'     => $orders->whereClient($clientId)->paginate(1, 'orders'),
```




Try this patch:
```diff
--- a/system/BaseModel.php
+++ b/system/BaseModel.php
@@ -1073,7 +1073,8 @@ abstract class BaseModel
      */
     public function paginate(?int $perPage = null, string $group = 'default', ?int $page = null, int $segment = 0)
     {
-        $pager = Services::pager(null, null, false);
+        // Since multiple models may use the Pager, the Pager must be shared.
+        $pager = Services::pager();
 
         if ($segment) {
             $pager->setSegment($segment, $group);
```

@kenjis Perfect, now it's working as expected. 

![CleanShot 2022-06-30 at 11 32 29@2x](https://user-images.githubusercontent.com/36922215/176644262-3d31de76-b102-47e7-97bc-7bc7b28a15bb.png)





Patch:
diff --git a/system/BaseModel.php b/system/BaseModel.php
index 39bd9ce2cb4c..c437a095407e 100644
--- a/system/BaseModel.php
+++ b/system/BaseModel.php
@@ -1073,7 +1073,8 @@ public function errors(bool $forceDB = false)
      */
     public function paginate(?int $perPage = null, string $group = 'default', ?int $page = null, int $segment = 0)
     {
-        $pager = Services::pager(null, null, false);
+        // Since multiple models may use the Pager, the Pager must be shared.
+        $pager = Services::pager();
 
         if ($segment) {
             $pager->setSegment($segment, $group);


Test patch:
diff --git a/tests/system/Models/PaginateModelTest.php b/tests/system/Models/PaginateModelTest.php
index ae93f2f6c62b..a2361b350246 100644
--- a/tests/system/Models/PaginateModelTest.php
+++ b/tests/system/Models/PaginateModelTest.php
@@ -79,4 +79,30 @@ public function testPaginatePageOutOfRange(): void
         $this->model->paginate(1, 'default', 500);
         $this->assertSame($this->model->pager->getPageCount(), $this->model->pager->getCurrentPage());
     }
+
+    public function testMultiplePager(): void
+    {
+        $_GET = [];
+
+        $validModel = $this->createModel(ValidModel::class);
+        $userModel  = $this->createModel(UserModel::class);
+
+        $validModel->paginate(1, 'valid');
+        $userModel->paginate(1, 'user');
+        $pager = $this->model->pager;
+
+        $this->assertSame($userModel->pager, $validModel->pager);
+
+        $this->assertSame(4, $validModel->countAllResults());
+        $this->assertSame(4, $userModel->countAllResults());
+
+        $this->assertStringContainsString('?page_valid=1"', $pager->links('valid'));
+        $this->assertStringContainsString('?page_valid=2"', $pager->links('valid'));
+        $this->assertStringContainsString('?page_valid=3"', $pager->links('valid'));
+        $this->assertStringContainsString('?page_valid=4"', $pager->links('valid'));
+        $this->assertStringContainsString('?page_user=1"', $pager->links('user'));
+        $this->assertStringContainsString('?page_user=2"', $pager->links('user'));
+        $this->assertStringContainsString('?page_user=3"', $pager->links('user'));
+        $this->assertStringContainsString('?page_user=4"', $pager->links('user'));
+    }
 }