Comments (8)
Seems, problem here:
data/src/Paginator/KeysetPaginator.php
Line 309 in 55fd808
For post_id
method name is getPost_id
.
May be we can remove magic here?
from data.
Removing magic is good. How would you do it?
from data.
Ok, that is an issue too, but after I update it to $methodName = 'get' . (new Inflector())->toPascalCase($field);
then I will get this error:
Error: Object of class DateTimeImmutable could not be converted to string in /app/vendor/yiisoft/data/src/Paginator/KeysetPaginator.php:264
Stack trace:
#0 /app/vendor/yiisoft/data/src/Paginator/KeysetPaginator.php(176): Yiisoft\Data\Paginator\KeysetPaginator->readData(Object(Yiisoft\Yii\Cycle\Data\Reader\EntityReader), Object(Yiisoft\Data\Reader\Sort))
#1 /app/views/blog/comments/_comments.php(19): Yiisoft\Data\Paginator\KeysetPaginator->read()
#2 /app/vendor/yiisoft/view/src/PhpTemplateRenderer.php(28): require('/app/views/blog...')
#3 /app/vendor/yiisoft/view/src/PhpTemplateRenderer.php(37): Yiisoft\View\PhpTemplateRenderer->Yiisoft\View\{closure}('/app/views/blog...', Array)
#4 /app/vendor/yiisoft/view/src/ViewTrait.php(449): Yiisoft\View\PhpTemplateRenderer->render(Object(Yiisoft\View\WebView), '/app/views/blog...', Array)
#5 /app/vendor/yiisoft/view/src/ViewTrait.php(402): Yiisoft\View\WebView->renderFile('/app/views/blog...', Array)
#6 /app/views/blog/comments/index.php(25): Yiisoft\View\WebView->render('_comments', Array)
#7 /app/vendor/yiisoft/view/src/PhpTemplateRenderer.php(28): require('/app/views/blog...')
#8 /app/vendor/yiisoft/view/src/PhpTemplateRenderer.php(37): Yiisoft\View\PhpTemplateRenderer->Yiisoft\View\{closure}('/app/views/blog...', Array)
#9 /app/vendor/yiisoft/view/src/ViewTrait.php(449): Yiisoft\View\PhpTemplateRenderer->render(Object(Yiisoft\View\WebView), '/app/views/blog...', Array)
#10 /app/vendor/yiisoft/view/src/ViewTrait.php(402): Yiisoft\View\WebView->renderFile('/app/views/blog...', Array)
#11 /app/vendor/yiisoft/yii-view/src/ViewRenderer.php(322): Yiisoft\View\WebView->render('index', Array)
#12 /app/vendor/yiisoft/yii-view/src/ViewRenderer.php(119): Yiisoft\Yii\View\ViewRenderer->renderProxy('index', Array, Array, Array, Array, Array)
#13 /app/vendor/yiisoft/data-response/src/DataResponse.php(324): Yiisoft\Yii\View\ViewRenderer->Yiisoft\Yii\View\{closure}()
#14 /app/vendor/yiisoft/data-response/src/Formatter/HtmlDataResponseFormatter.php(43): Yiisoft\DataResponse\DataResponse->getData()
#15 /app/vendor/yiisoft/data-response/src/DataResponse.php(353): Yiisoft\DataResponse\Formatter\HtmlDataResponseFormatter->format(Object(Yiisoft\DataResponse\DataResponse))
#16 /app/vendor/yiisoft/data-response/src/DataResponse.php(106): Yiisoft\DataResponse\DataResponse->formatResponse()
#17 /app/vendor/yiisoft/cookies/src/CookieMiddleware.php(148): Yiisoft\DataResponse\DataResponse->getHeader('Set-Cookie')
#18 /app/vendor/yiisoft/cookies/src/CookieMiddleware.php(85): Yiisoft\Cookies\CookieMiddleware->encodeResponseSetCookieHeaders(Object(Yiisoft\DataResponse\DataResponse))
#19 /app/vendor/yiisoft/middleware-dispatcher/src/MiddlewareStack.php(104): Yiisoft\Cookies\CookieMiddleware->process(Object(HttpSoft\Message\ServerRequest), Object(Psr\Http\Server\RequestHandlerInterface@anonymous))
#20 /app/vendor/yiisoft/session/src/SessionMiddleware.php(36): Psr\Http\Server\RequestHandlerInterface@anonymous->handle(Object(HttpSoft\Message\ServerRequest))
#21 /app/vendor/yiisoft/middleware-dispatcher/src/MiddlewareStack.php(104): Yiisoft\Session\SessionMiddleware->process(Object(HttpSoft\Message\ServerRequest), Object(Psr\Http\Server\RequestHandlerInterface@anonymous))
#22 /app/vendor/yiisoft/error-handler/src/Middleware/ErrorCatcher.php(135): Psr\Http\Server\RequestHandlerInterface@anonymous->handle(Object(HttpSoft\Message\ServerRequest))
#23 /app/vendor/yiisoft/middleware-dispatcher/src/MiddlewareStack.php(104): Yiisoft\ErrorHandler\Middleware\ErrorCatcher->process(Object(HttpSoft\Message\ServerRequest), Object(Psr\Http\Server\RequestHandlerInterface@anonymous))
#24 /app/vendor/yiisoft/middleware-dispatcher/src/MiddlewareStack.php(53): Psr\Http\Server\RequestHandlerInterface@anonymous->handle(Object(HttpSoft\Message\ServerRequest))
#25 /app/vendor/yiisoft/middleware-dispatcher/src/MiddlewareDispatcher.php(50): Yiisoft\Middleware\Dispatcher\MiddlewareStack->handle(Object(HttpSoft\Message\ServerRequest))
#26 /app/vendor/yiisoft/yii-http/src/Application.php(87): Yiisoft\Middleware\Dispatcher\MiddlewareDispatcher->dispatch(Object(HttpSoft\Message\ServerRequest), Object(App\Handler\NotFoundHandler))
#27 /app/vendor/yiisoft/yii-runner-http/src/HttpApplicationRunner.php(103): Yiisoft\Yii\Http\Application->handle(Object(HttpSoft\Message\ServerRequest))
#28 /app/public/index.php(36): Yiisoft\Yii\Runner\Http\HttpApplicationRunner->run()
#29 {main}
from data.
I had some time to dig deeper into it.
As @vjik said it is a problem, because it will try to call getCreated_at
method.
If I replace it with
$methodName = 'get' . (new Inflector())->toPascalCase($field);
, then it will be OK, but it is still magic.
The next issue is with the following line:
data/src/Paginator/KeysetPaginator.php
Line 262 in 55fd808
If the
getValueFromItem
returns a \DateTimeInterface
then it is not possible to cast it to string.
data/src/Paginator/KeysetPaginator.php
Line 309 in 55fd808
I made a new method:
/**
* @param mixed $item
*
* @return mixed
*/
private function getStringValueFromItem($item, string $field): string
{
$value = $this->getValueFromItem($item, $field);
if ($value instanceof \DateTimeImmutable) {
return (string) $value->getTimestamp();
}
return (string) $value;
}
And I replaced these two lines:
data/src/Paginator/KeysetPaginator.php
Line 262 in 55fd808
data/src/Paginator/KeysetPaginator.php
Line 268 in 55fd808
to:
$this->currentFirstValue = $this->getStringValueFromItem($item, $field);
and
$this->currentLastValue = $this->getStringValueFromItem($item, $field);
After these modifications it sorts well for datetime fields too.
Of course there may be more values that cannot be casted to string.
from data.
Is there any reason the KeysetPaginator
class is final
?
I like in Yii 2.0 that I can easily extend the classes of the framework and I can use it if I configure it in the config files.
Now I would like to extend the KeysetPaginator
class and fix it with my own methods while it is not fixed in this repository.
But it is not possible since this class is final
.
from data.
I realised that KeysetPaginator
is not good for my scenario (I just picked it from the demo app).
Because if I want to order by date, there could be multiple records with the same date, and KeysetPaginator
will not know by the token which was the last record with the same date.
So I found OffsetPaginator
which works great for my scenario.
from data.
@albertborsos would you please submit pull requests with your changes? Preferably separate ones but one PR would do as well.
Classes are final by default in Yii3. There are many advantages and disadvantages in this decision but that's how it is.
from data.
I close this issue, since I made a PR to access the field with the getter method.
The other issue I think is not a bug, I just used the wrong pagiantor.
from data.
Related Issues (20)
- Add `iterable` support in `DataProcessorInterface` HOT 1
- Paginator refactoring concept HOT 2
- Remove `PaginatorInterface` HOT 2
- Increase test coverage to 100%
- Rename filter processor to handler
- Improve namespacing HOT 1
- Move `FilterDataValidationHelper::assertFilterHandlerIsIterable()` method to `Iterable` namespace HOT 2
- Allow pass criteria array to `Group` (reader) filter constructor HOT 1
- Throws exception when pass to `IterableDataReader` non-`IterableFilterHandlerInterface` filter handlers HOT 2
- Make accessing item methods explicit or not? HOT 2
- Add suffix `Handler` for all filter handlers HOT 1
- Finalize `IterableDataReader` HOT 4
- Rename `withFilterHandlers()` to `withAddedFilterHandlers()` into `FilterableDataInterface`
- Remove scrutinizer
- Class Yiisoft\Yii\Cycle\Data\Reader\FilterHandler\AllHandler contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Yiisoft\Data\Reader\FilterHandlerInterface::getFilterClass) HOT 3
- update irc link
- Reuse tests for all data packages
- Add `ILike` filter
- Find a test case with multibyte strings for `Like` and `ILike` filter handlers
- Do not preserve keys of filtered items in iterable data reader HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from data.