Open Chrysweel opened 11 years ago
I'll try to reproduce this issue asap.
thanks @stephpy Any idea? : )
I'm sorry, i'm busy at this moment, i'll look at this as soon as possible
Ok No problem! : )
Any update on this? Seeing the same thing.
I'll have a look on it this week, sorry ...
Awesome, thanks
I created exactly same context, but i have not this issue :s
What do you do on twig template ? if you only iterate on results, it's throw the exception ?
It seems somewhere something try to cast in string the Component which is very very weird. It's dirty, but you could add a __toString method on your Entity/Component ... May it'll fix your issue.
public function __toString()
{
return $this->getId();
}
Can you paste me your twig file ? I can't define at this moment where/when a string cast is made on component :\
WHERE s0_.type = ? AND s0_.context = ? AND s0_.subject_id = ?
ORDER BY s0_.created_at DESC) dctrn_result) dctrn_table' with params {"1":"timeline","2":"ESTADO","3":{}}:
In exception, it seems subject_id is {} ... it should be the of compoennt id, weird.
This is my twig template.
{% for action in timeline %}
<div class="notificacion">
<div class="container-fluid">
<div class="row-fluid">
{{ timeline_render(action) }}
</div>
</div>
</div>
<hr/>
{% else %}
<p>{{ 'timeline.noAction' | trans({}, 'timeline') }}</p>
{% endfor %}
And the controller is :
/**
* @Template
*/
public function myTimelineAction($u = null)
{
if ($u == null) $u = $this->get('security.context')->getToken()->getUser();
$actionManager = $this->get('spy_timeline.action_manager');
$subject = $actionManager->findOrCreateComponent($u);
$timeline = $actionManager->getSubjectActions($subject);
return array('timeline' => $timeline, 'usuario'=> $u);
}
There's nothing freak ... did you try to put __toString method on Component ?
If you comment {{ timeline_render }}, do you still have this exception ?
I dont know.
This is what I have.
config.yml of timeline
#timeline
spy_timeline:
paginator: spy_timeline.paginator.knp
drivers:
orm:
object_manager: doctrine.orm.entity_manager
classes:
query_builder: ~ # Spy\TimelineBundle\Driver\ORM\QueryBuilder\QueryBuilder
timeline: ant\SocialBundle\Entity\Timeline
action: ant\SocialBundle\Entity\Action
component: ant\SocialBundle\Entity\Component
action_component: ant\SocialBundle\Entity\ActionComponent
filters:
duplicate_key:
priority: 10
data_hydrator:
priority: 20
filter_unresolved: true
locators:
- spy_timeline.filter.data_hydrator.locator.doctrine_orm
render:
path: 'SocialBundle:Timeline/verbs'
fallback: 'SocialBundle:Timeline:default.html.twig'
resources:
- 'MyBundle:Timeline:components.html.twig'
My twig template
{% for action in timeline %}
<div class="notificacion">
<div class="container-fluid">
<div class="row-fluid">
{{ timeline_render(action) }}
</div>
</div>
</div>
<hr/>
{% else %}
<p>{{ 'timeline.noAction' | trans({}, 'timeline') }}</p>
{% endfor %}
{{ knp_pagination_render(timeline) }}
My component.php
<?php
namespace ant\SocialBundle\Entity;
use Spy\TimelineBundle\Entity\Component as BaseComponent;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="spy_timeline_component")
*/
class Component extends BaseComponent
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __toString()
{
return $this->getId();
}
}
And my controller
/**
* @Template
*/
public function myTimelineAction($u = null)
{
if ($u == null) $u = $this->get('security.context')->getToken()->getUser();
$actionManager = $this->get('spy_timeline.action_manager');
$subject = $actionManager->findOrCreateComponent($u);
$timeline = $actionManager->getSubjectActions($subject, array('page' => 1, 'max_per_page' => '3', 'paginate' => true));
return array('timeline' => $timeline, 'usuario'=> $u);
}
And I get the same error. :_(
And yes !!
If I comment this line:
{# {{ timeline_render(action) }} #}
I get the error.
How can I use the pagination of timeline bundle ?? Maybe the problem is knpPaginator...
Mmmh, what is {{ knp_pagination_render(timeline) }}
?
Try to comment it ...
If you setted __toString
method on your ant\SocialBundle\Entity\Component
, you could not have this error
Catchable Fatal Error: Object of class ant\SocialBundle\Entity\Component could not be converted to string
Edit it and retry:
public function __toString()
{
return (string) $this->getId();
}
How can I use the pagination of timeline bundle ?? Maybe the problem is knpPaginator...
You tried without knp paginator ? I guess you did.
If it's not throw an exception, uncomment for
and
{{ knp_pagination_render(timeline) }} is to use knp_paginator. It show the select of pagination.
If I comment it, I see 3 actions, but I cant choose more pages.
I modified it:
public function __toString()
{
return (string) $this->getId();
}
And now, in my timeline, I dont see none action. The timeline is empty. But I dont get error.
To use without knp paginator that I have to write ?
I did same documentation: https://github.com/stephpy/TimelineBundle/blob/master/Resources/doc/pagination.markdown
$timeline = $actionManager->getSubjectActions($subject, array('page' => 1, 'max_per_page' => '3', 'paginate' => true));
spy_timeline:
paginator: ~
Because I don't see the select of choose page of pagination, how include it in my template twig ... ?
Thanks for help me! : )
That's the knp_pagination_render which make this fail by this way.
You can remove __toString
method on Component
.
$timeline is not an instanceof Knp\Component\Pager\Paginator
but an instanceof Spy\Timeline\ResultBuilder\Pager\KnpPager
which make the trouble i guess.
There is 2 solutions:
You define your own macro for Spy\Timeline\ResultBuilder\Pager\PagerInterface
classes, or try:
{{ knp_pagination_render(timeline.iterator) }}
$pager->getIterator() will return an object managed by Knp\Paginator component :)
Let me know.
aaahmmm I think it doesnt work.
I changed, {{ knp_pagination_render(timeline.iterator) }} in my template twig And my timeline, is empty...
Now, I deleted the __tostring method on Component. I get the same error....
How can I use the pagination timeline, without use the pagination Knp ??
I did'nt try with this use case (with pagination render), i'll look at this tomorrow.
If you can't wait, as i said, you have a https://github.com/stephpy/timeline/blob/master/src/Spy/Timeline/ResultBuilder/Pager/PagerInterface.php object, and you'll be able on your twig to deal with that
{% if timeline.haveToPaginate %}
{% set lastPage = timeline.lastPage %}
{% set currentPage = timeline.page %}
....
{% endif %
That's sure this error comes from this pagination renderer, by this way, i should have the same issue at home.
I found issue, i tested with old version of KnpPaginatorBundle which changes his method to fetch number of results to paginate.
There is an issue on their new behavior, doctrine allow to give as parameter a object which has doctrine metadata and will automatically return primary keys on SQL.
KnpPaginatorBundle expects scalar results and by this way ... it fails ...
You still have to use timeline.iterator
look documentation
Really, really sorry for delay.
@stephpy nothing has changed. I updated the timeline bundle! But my timeline is empty!
I repeat my code ok ? Maybe you see some wrong. My config.yml
spy_timeline:
paginator: spy_timeline.paginator.knp
drivers:
orm:
object_manager: doctrine.orm.entity_manager
classes:
query_builder: ~
timeline: ant\SocialBundle\Entity\Timeline
action: ant\SocialBundle\Entity\Action
component: ant\SocialBundle\Entity\Component
action_component: ant\SocialBundle\Entity\ActionComponent
filters:
duplicate_key:
priority: 10
data_hydrator:
priority: 20
filter_unresolved: true
locators:
- spy_timeline.filter.data_hydrator.locator.doctrine_orm
render:
path: 'SocialBundle:Timeline/verbs'
fallback: 'SocialBundle:Timeline:default.html.twig'
resources:
- 'MyBundle:Timeline:components.html.twig'
My twig template
{% for action in timeline %}
<div class="notificacion">
<div class="container-fluid">
<div class="row-fluid">
{{ timeline_render(action) }}
</div>
</div>
</div>
<hr/>
{% else %}
<p>{{ 'timeline.noAction' | trans({}, 'timeline') }}</p>
{% endfor %}
{{ knp_pagination_render(timeline.iterator) }}
And my controller:
/**
* @Template
*/
public function myTimelineAction($u = null)
{
if ($u == null) $u = $this->get('security.context')->getToken()->getUser();
$actionManager = $this->get('spy_timeline.action_manager');
$subject = $actionManager->findOrCreateComponent($u);
$timeline = $actionManager->getSubjectActions($subject, array('page' => 1, 'max_per_page' => '3', 'paginate' => true));
return array('timeline' => $timeline, 'usuario'=> $u);
}
Is all correct ? I dont get the error, but the timeline is empty...
I'll give a new try this night.
Without paginate => true option, you have some actions ? What is the version of your knpPaginatorBundle knpComponents ?
I tried with same configuration and i had no issue. May version of KnpPaginatorBundle/KnpComponents is not the same.
This my version of knp.
"knplabs/knp-paginator-bundle": "2.3.*@dev",
If you know a version that works with the pagination of timeline , you tell me and I change! : ) Or show me the code correct to pagination, only I want that work the pagination! XD
I used exactly same code.
Can you answer to this question please:
Without paginate => true option, you have some actions ?
It's anormal, could you dump me that.
public function myTimelineAction($u = null)
{
if ($u == null) $u = $this->get('security.context')->getToken()->getUser();
$actionManager = $this->get('spy_timeline.action_manager');
$subject = $actionManager->findOrCreateComponent($u);
$timeline = $actionManager->getSubjectActions($subject, array('page' => 1, 'max_per_page' => '3', 'paginate' => true));
var_dump(count($timeline));
return array('timeline' => $timeline, 'usuario'=> $u);
}
It's important for me to know if without pagination you have results, and without no.
Yes ! With " pagination = true " my timeline is empty, and my var_dump(count($timeline)); = int(0). With "pagination = false " my timeline is correct, and my var_dump(count($timeline)); = int(3);
Weird :s If you're comfortable with sql, you could look at difference between SQL requests with pagination and without. (in sf debug tool bar). Execute theses SQL requests and you'll be able to know why 0 actions are returned. This behavior does not occur at me.
If you are not comfortable with sql, please, paste me theses requests.
Hello @stephpy sorry for delay.
The difference between the call with and without paginate is this call to mysql:
SELECT COUNT(*) AS dctrncount FROM (SELECT DISTINCT id6 FROM (SELECT s0.verb AS verb0, s0_.status_current AS statuscurrent1, s0.status_wanted AS statuswanted2, s0.duplicate_key AS duplicatekey3, s0.duplicate_priority AS duplicatepriority4, s0.created_at AS createdat5, s0.id AS id6, s1.type AS type7, s1.text AS text8, s1.id AS id9, s2.model AS model10, s2.identifier AS identifier11, s2.hash AS hash12, s2.id AS id13, s1.action_id AS actionid14, s1.component_id AS component_id15 FROM spy_timelineaction s0 INNER JOIN spy_timeline_actioncomponent s3 ON s0.id = s3.actionid AND ((s3.actionid = s0.id AND s3_.componentid = 'subject' AND s3.type = 109)) LEFT JOIN spy_timeline_actioncomponent s1 ON s0.id = s1.action_id LEFT JOIN spy_timelinecomponent s2 ON s1_.componentid = s2.id WHERE s0_.statuscurrent = 'published' ORDER BY s0.created_at DESC) dctrn_result) dctrn_table
This SQL request is with paginate, when I have paginate false, this request doesnt exist...
this help to you?
Another discovery If I have in my config:
spy_timeline:
paginator: ~
And in my template:
{% if timeline.haveToPaginate %}
{% set lastPage = timeline.lastPage %}
{% set currentPage = timeline.page %}
{% endif %}
{{ lastPage }}
{{ currentPage }}
{{ knp_pagination_render(timeline.iterator) }}
I see the last Page and the currentPage. 5 and 1 respectively.
But the line {{ knp_pagination_render(timeline.iterator) }} show the error:
FatalErrorException: Error: Call to undefined method ArrayIterator::getTemplate() in /var/www/workspace/myproject/vendor/knplabs/knp-paginator-bundle/Knp/Bundle/PaginatorBundle/Twig/Extension/PaginationExtension.php line 56
Hi everybody... Same werid problem here. If using
paginator: spy_timeline.paginator.knp
and doing
$timeline = $actionManager->getSubjectActions($subject,
array('page' => 1, 'max_per_page' => '10', 'paginate' => true));
I got an empty resultset.
If I set the last parameter to false, i will get the expected results.
Is there something that i'm missing?
Thanks
Hello. I get the following error to paginate:
I tried the two configuration:
My config actually is:
My controller is:
And I get the following error: