How to make this extended pagination in yii2?

Good time of day. There is such pagination(this is the layout of the portal you want to put in yii2).
In the portal, when I added pagination received the following
5e49bb1408a56264069150.jpeg

That gave the framework by default - not quite what I need. The picture below shows the desired result.
5e4aac19bf84b493944684.jpeg
April 7th 20 at 15:23
2 answers
April 7th 20 at 15:25
Solution
Very simple. Change default settings in the DI container of this class.

1. Using a DI Container
<?php

declare(strict_types=1);

namespace frontend\bootstrap;

use Yii;
use yii\base\BootstrapInterface;
use yii\di\Container;
use yii\widgets\Without;

/**
 * @author Maxim Vorozhtsov <myks1992@mail.ru>
*/
class Bootstrap implements BootstrapInterface
{
/**
 * @inheritDoc
*/
 public function bootstrap($app)
{
 /** @var Container $container */
 $container = Yii::$container;

 $container->set(Without::class, [
 'prevPageLabel' => false,
 'nextPageLabel' => false,
 'maxButtonCount' => 3,
]);
}
}

As DI can be infused in the config. I usually set up there, but someone creates a bootstrap file. Here too you can choose. I choose config. Here's an example:
'container' => [
 'singletons' => [
 CheckAccessInterface::class => yii\rbac\DbManager::class,
 IdentityInterface::class => function () {
 return Yii::$app->user->getIdentity();
},
],
 ],

But to understand designed in bootstrap. To work remember to put this class into the Bootstrap section of the config file:
'bootstrap' => [
frontend\bootstrap\Bootstrap::class
 ],


2. C create a class that inherited from base
<?php

declare(strict_types=1);

namespace frontend\widgets;

class Without extends \yii\widgets\Without
{
 public $prevPageLabel = false;
 public $nextPageLabel = false;
 public $maxButtonCount = 3;
}


And use as usual. If you want to replace in the DataProvider use the DI container. Either make the class its own:
Yii::$container->set('yii\widgets\Without', 'frontend\widgets\Without');
First, you misunderstood the question: you need to do as the link, and not, as in the screenshot. Second, the parameters set in the DI will not function after a call Without::widget() and passing it any parameters, and it is necessary to pass a parameter to the pagination. After the call Without::widget() with pagination transferred all the settings like maxButtonCount reset. - Ali commented on April 7th 20 at 15:28
@Magdalena28,

1. Are you not the right question to put, and understood me. Ask questions deployed. Like not the first day on the toaster and don't know that well asked question - half of answer. I understood You correctly. Any change in pagination is associated with this file. I took off not ready decision, and the documentation of this class. Customize for themselves.

2. DI is one way. You now accuse me of your incomplete question. How do I know how you are going to use. If you have lost something in the constructor - that means you can't use DI. Classes to work with DI we need to create using new (), and using Yii:createObject([...]). Then DI will pull all the dependencies.

You can also create a class App\Without::class inherited from a base in it to replace the necessary settings and you also will have to work. This is also a good practice.

Once again I repeat. I showed you where this is configured, and how and where you will set up another question. Can even on every page to pass parameters. - Selmer_Miller65 commented on April 7th 20 at 15:31
hmm, actually the question I asked)
pagination in the picture - that gave me yii2(read here how to make pagination).
It's not quite what I need. Need for the link
I just don't know how to conjure. Google did not help. That written, I do not understand, show the example code, please. - sydnie_Da commented on April 7th 20 at 15:34
I'm not the author of the question.

At the time I tried to do this:
Yii::$container->set('yii\widgets\Without', ['maxButtonCount' => 5]);

Without echo::widget(['pagination' => $pagination]);

But the output of buttons was still 10 (the default value). - Ali commented on April 7th 20 at 15:37
@jayce.Sawayn, @Magdalena28 Yes. Something I do the night beguiled!) @jayce.Sawaynwell. Once I get You confused Here are two examples:

1. Using a DI Container
<?php

declare(strict_types=1);

namespace frontend\bootstrap;

use Yii;
use yii\base\BootstrapInterface;
use yii\di\Container;
use yii\widgets\Without;

/**
 * @author Maxim Vorozhtsov <myks1992@mail.ru>
*/
class Bootstrap implements BootstrapInterface
{
/**
 * @inheritDoc
*/
 public function bootstrap($app)
{
 /** @var Container $container */
 $container = Yii::$container;

 $container->set(Without::class, [
 'prevPageLabel' => false,
 'nextPageLabel' => false,
 'maxButtonCount' => 3,
]);
}
}

As DI can be infused in the config. I usually set up there, but someone creates a bootstrap file. Here too you can choose. I choose config. Here's an example:
'container' => [
 'singletons' => [
 CheckAccessInterface::class => yii\rbac\DbManager::class,
 IdentityInterface::class => function () {
 return Yii::$app->user->getIdentity();
},
],
 ],

But to understand designed in bootstrap. To work remember to put this class in the section Bootstrap:
'bootstrap' => [
frontend\bootstrap\Bootstrap::class
 ],


2. C create a class that inherited from base
<?php

declare(strict_types=1);

namespace frontend\widgets;

class Without extends \yii\widgets\Without
{
 public $prevPageLabel = false;
 public $nextPageLabel = false;
 public $maxButtonCount = 3;
}


And use as usual. If you want to replace in the DataProvider use the DI container. Either make the class its own:
Yii::$container->set('yii\widgets\Without', 'frontend\widgets\Without');
- Selmer_Miller65 commented on April 7th 20 at 15:40
@Magdalena28, I don't know what you have there is not working. Let's see how the calculation of the number of buttons and maybe you will understand that You don't do that. Can used not that Without which is applied in the DI. All I know I can't. I see that in the source code it should not affect. He will not change this number even if you transfer your Paginator. - Selmer_Miller65 commented on April 7th 20 at 15:43
@Eldon_Ry, thanks for the help! the incident a misunderstanding - my fault, should have shown two pictures(which gave the frame and what you need), corrected the issue. I noticed that you removed in the code, prev, next. In fact, they need, plus apart from them, we need two buttons which are at the very beginning and the very end. - sydnie_Da commented on April 7th 20 at 15:46
@jayce.Sawayn, in principle, it was possible not to dilute this discussion) These simple questions so long discussed. It was enough just to see what public properties are and replace them. In the documentation it is written what to a public property that changes. But I gave You a turnkey solution. At the same time showed how it can be infused. Question popular, so let it be. What matters is that You had an understanding and I think it is! Not for that!) - Selmer_Miller65 commented on April 7th 20 at 15:49
@Eldon_Ry, I was wrong. yii\widgets\Without globally set via Yii::$container->set() is possible. I tried the same way to configure the yii\data\Pagination, namely, defaultPageSize, pageSize, forcePageParam, but it does not work. - Ali commented on April 7th 20 at 15:52
April 7th 20 at 15:27
Solution
Links to the first and last page are configured via firstPageLabel and lastPageLabel. Links to previous and next page through prevPageLabel and nextPageLabel. The number of page buttons — using maxButtonCount. Documentation.

Example of submission:
Without echo::widget([
 'pagination' => $pagination,
 'maxButtonCount' => 7,
 'firstPageLabel' => 'Home',
 'lastPageLabel' => 'End',
]);
Example of submission:
Without echo::widget([
 'pagination' => $pagination,
 'maxButtonCount' => 7,
 'firstPageLabel' => 'Home',
 'lastPageLabel' => 'End',
]);
I hesitate to ask what Your answer differs from mine?)) In addition even gave an example and is not correct. The answer seems to have understood what and how, but sense is not enough to draw properly or what?))

That's what the author asks for your answer:
Without echo::widget([
 'prevPageLabel' => false,
 'nextPageLabel' => false,
 'maxButtonCount' => 3,
]);

But now the main thing. What will you do Without if you are using this on multiple pages? And how you will change if you are using DataProvider? - Selmer_Miller65 commented on April 7th 20 at 15:30
@Eldon_Ry, the author asks is:
5e49d6d6aa760094447530.png
Here there are buttons for first, previous, next and last pages. - Ali commented on April 7th 20 at 15:33
@Magdalena28strange. On my phone those icons do not appear. - Selmer_Miller65 commented on April 7th 20 at 15:36
@Eldon_Ry, I uploaded the layout on surge.sh for demonstration to the customer, resources are not cached, pictures appear a bit later when loaded. - sydnie_Da commented on April 7th 20 at 15:39
in General, I have come to this option, now you understand where to put it to apply globally
use yii\helpers\Html;

Yii::$container->set('yii\widgets\Without', [
 'maxButtonCount' => 3,
 'prevPageLabel' => Html::img(Yii::$app->urlManager->createUrl('img/svg/icon-chevrons-left-gray.svg'), ['alt' => 'ago']),
 'nextPageLabel' => Html::img(Yii::$app->urlManager->createUrl('img/svg/icon-chevrons-right-gray.svg'), ['alt' => 'forward']),
 'firstPageLabel' => Html::img(Yii::$app->urlManager->createUrl('img/svg/icon-skip-back-gray.svg'), ['alt' => 'home']),
 'lastPageLabel' => Html::img(Yii::$app->urlManager->createUrl('img/svg/icon-skip-forward-gray.svg'), ['alt' => 'end']),
]);
- sydnie_Da commented on April 7th 20 at 15:42
@jayce.Sawayn,
pictures appear later when loaded.
that's why the confusion happened)

in General, I have come to this option, now you understand where to put it to apply globally


Right here:
namespace frontend\bootstrap;

use Yii;
use yii\base\BootstrapInterface;
use yii\di\Container;
use yii\widgets\Without;

/**
 * @author Maxim Vorozhtsov <myks1992@mail.ru>
*/
class Bootstrap implements BootstrapInterface
{
/**
 * @inheritDoc
*/
 public function bootstrap($app)
{
 /** @var Container $container */
 $container = Yii::$container;

 $container->set(Without::class, [
 'maxButtonCount' => 3,
 'prevPageLabel' => Html::img($app->urlManager->createUrl('img/svg/icon-chevrons-left-gray.svg'), ['alt' => 'ago']),
 'nextPageLabel' => Html::img($app->urlManager->createUrl('img/svg/icon-chevrons-right-gray.svg'), ['alt' => 'forward']),
 'firstPageLabel' => Html::img($app->urlManager->createUrl('img/svg/icon-skip-back-gray.svg'), ['alt' => 'home']),
 'lastPageLabel' => Html::img($app->urlManager->createUrl('img/svg/icon-skip-forward-gray.svg'), ['alt' => 'end']),

]);
}
}


in web-fonfig.php
'bootstrap' => [
frontend\bootstrap\Bootstrap::class
 ],
- Selmer_Miller65 commented on April 7th 20 at 15:45
@Eldon_Ry, thanks, this is exactly what I needed)
only I added in frontend/config/main.php and it worked) - sydnie_Da commented on April 7th 20 at 15:48
@jayce.Sawaynin the application template there is a file config/bootstrap.php there you can add Yii::$container->set(...) without any classes. And then there is the file common/config/bootstrap.php. - Ali commented on April 7th 20 at 15:51
@Magdalena28, config/bootstrap.php this is not me, but in common/config/bootstrap.php already posted, but the site crashed. Perhaps this is due to using yii\helpers\Html; - sydnie_Da commented on April 7th 20 at 15:54
@jayce.Sawayn, frontend/config/bootstrap.php if to be more exact. And for the backend, too, have such a file. - Ali commented on April 7th 20 at 15:57

Find more questions by tags Yii