<?php declare(strict_types=1);
namespace app\widgets;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use \yii\widgets\LinkPager as DefaultLinkPager;
class CustomLinkPager extends DefaultLinkPager
{
}
renderPageButton
и renderPageButtons
. В них по факту мне нужно поменять:$linkWrapTag = ArrayHelper::remove($options, 'tag', 'li');
на $linkWrapTag = ArrayHelper::remove($options, 'tag');
renderPageButtons
) сделать тоже самое.renderPageButton
у меня получилось провернуть такую операцию:protected function renderPageButton($label, $page, $class, $disabled, $active): string
{
parent::renderPageButton($label, $page, $class, $disabled, $active);
$options = $this->linkContainerOptions;
$linkWrapTag = ArrayHelper::remove($options, 'tag');
$linkOptions = $this->linkOptions;
$linkOptions['data-page'] = $page;
return Html::tag($linkWrapTag, Html::a($label, $this->pagination->createUrl($page), $linkOptions), $options);
}
renderPageButtons
у меня никак не выходит. Не пойму как оформить правильно. private function checkString(string $string): void
{
$this->incomingString = mb_strtolower(preg_replace('#[^\p{Cyrillic}\p{Latin}]#u', '', $string));
$this->preparedString = $this->incomingString;
$this->lengthString = mb_strlen($this->preparedString);
}
__get()
, что бы получить доступ к приватному свойству, т.е. к датам),а в классе Interval скорректировал метод по подсчету разницу в днях:public function toDays(): string
{
$startDate = strtotime($this->startDate->date);
$endDate = strtotime($this->endDate->date);
$diff = ($endDate - $startDate)/(60*60*24);
return 'Разница (в днях) между датами = ' . abs($diff) . '.';
}
array (size=3)
0 =>
array (size=3)
0 => string '/api/items/20/John Dow' (length=22)
1 => string '/api/items/20/QA' (length=16)
2 => string '/api/items/20/100' (length=17)
1 =>
array (size=3)
0 => string '/api/items/20/John Dow' (length=22)
1 => string '/api/items/20/QA' (length=16)
2 => string '/api/items/20/100' (length=17)
2 =>
array (size=3)
0 => string '/api/items/20/John Dow' (length=22)
1 => string '/api/items/20/QA' (length=16)
2 => string '/api/items/20/100' (length=17)
public function getApiPath(): array
{
return array_map(function () {
return preg_replace_callback(
'#%(.*)%#isU',
function ($matches) {
return $this->employee[$matches[1]];
},
$this->template);
},
array_values($this->template));
}
<?php declare(strict_types=1);
class testAPI
{
private array $employee;
private array $template;
/**
* testAPI constructor.
* @param array $employee – массив с данными о работнике
* @param array $template — массив с шаблонами
*/
public function __construct(array $employee, array $template)
{
$this->employee = $employee;
$this->template = $template;
}
public function getApiPath(): array
{
return array_map(function () {
$regex = '#%(.*)%#isU';
return preg_replace_callback($regex, $this->prepareTemplate(), $this->template);
},
array_values($this->template));
}
private function prepareTemplate(): array
{
$result = [];
foreach ($this->employee as $key => $value) {
$tmp = str_replace("%$key%", $value, $this->template);
$result[] = $tmp;
}
var_dump($result);
exit;
}
}
$apiTemplatesSet1 = [
'/api/items/%id%/%name%',
'/api/items/%id%/%role%',
'/api/items/%id%/%salary%'
];
$user = [
'id' => 20,
'name' => 'John Dow',
'role' => 'QA',
'salary' => 100
];
$test = new testAPI($user, $apiTemplatesSet1);
var_dump($test->getApiPath());
Результат:
array (size=4)
0 =>
array (size=3)
0 => string '/api/items/20/%name%' (length=20)
1 => string '/api/items/20/%role%' (length=20)
2 => string '/api/items/20/%salary%' (length=22)
1 =>
array (size=3)
0 => string '/api/items/%id%/John Dow' (length=24)
1 => string '/api/items/%id%/%role%' (length=22)
2 => string '/api/items/%id%/%salary%' (length=24)
2 =>
array (size=3)
0 => string '/api/items/%id%/%name%' (length=22)
1 => string '/api/items/%id%/QA' (length=18)
2 => string '/api/items/%id%/%salary%' (length=24)
3 =>
array (size=3)
0 => string '/api/items/%id%/%name%' (length=22)
1 => string '/api/items/%id%/%role%' (length=22)
2 => string '/api/items/%id%/100' (length=19)
<?php declare(strict_types=1);
class testAPI
{
private array $data;
public function __construct(array $data)
{
$this->data = $data;
}
public function getApiPath(array $template): array
{
return array_map(function (array $template) {
$regex = '#%(.*)%#isU';
return preg_replace_callback($regex, $this->prepareTemplate(), $template);
},
array_values($template));
}
private function prepareTemplate()
{
// callback который будет производить замену
}
}
$apiTemplatesSet1 = [
'/api/items/%id%/%name%',
'/api/items/%id%/%role%',
'/api/items/%id%/%salary%'
];
$test = new testAPI([
'id' => 20,
'name' => 'John Dow',
'role' => 'QA',
'salary' => 100
]);
Да я в качестве тренеровки переношу шаблон, а там разметка сделана таким видом:
И выглядит:
Пытаюсь повторить