[TYPO3-mvc] Cannot cast object oftype"Tx_Extbase_Persistence_QueryResult" to string.
Johannes C. Schulz - EnzephaloN IT-Solutions
info at enzephalon.de
Mon Jun 13 13:05:59 CEST 2011
Hi Claus
Okay, here we have the fluid template:
<f:layout name="default" />
This Template is responsible for creating a table of domain objects.
<f:section name="main">
<h1>Listing for Teaseritem</h1>
<f:flashMessages />
<table>
<f:if condition="{pagination}==1">
<enzteaserlist:widget.paginate objects="{teaseritems}" as="teasers"
configuration="{itemsPerPage: itemsperpage,insertAbove:0,insertBelow:1}">
</f:if>
<f:for each="{teasers}" as="teaseritem">
<tr>
<td>
<f:image src="teaseritem.teaserimage"
alt="teaseritem.title" width="120c" height="120c"></f:image>
</td>
<td>
<f:if condition="{teaseritem.linkdetail}
==''">
<f:then>
<f:link.action
action="showitem" arguments="{teaseritem :
teaseritem}">{teaseritem.title}</f:link.action>
</f:then>
<f:else>
<f:link.page
pageUid="{teaseritem.linkdetail}">{teaseritem.title}</f:link.page>
</f:else>
</f:if>
{teaseritem.shortdescription}
</td>
<td>
{teaseritem.addinfo1}
{teaseritem.addinfo2}
{teaseritem.addinfo3}
{teaseritem.addinfotext}
<f:if condition=" {teaseritem.linkdetail} !=
''">
<f:then>
<f:link.page
pageUid="{teaseritem.linkdetail}"><img src="img/button_detail.png"
border="0"></f:link.page>
</f:then>
<f:else>
<f:link.action
action="showitem" arguments="{teaseritem : teaseritem}"><img
src="img/button_detail.png" border="0"></f:link.action>
</f:else>
</f:if>
<f:if condition=" {teaseritem.linkbooking}
!= ''">
<f:then>
<f:if
condition="{teaseritem.linkbooking} <= '10000'">
<f:then>
<f:link.page
pageUid="{teaseritem.linkbooking}"><img src="img/button_booking.png"
border="0"></f:link.page>
</f:then>
<f:else>
<f:link.external uri="{teaseritem.linkbooking}" target="_blank"><img
src="img/button_booking.png" border="0"></f:link.external>
</f:else>
</f:if>
</f:then>
</f:if>
</td>
</tr>
</f:for>
<f:if condition="{pagination}==1">
</enzteaserlist:widget.paginate>
</f:if>
</table>
</f:section>
Thanx alot
-----Ursprüngliche Nachricht-----
Von: typo3-project-typo3v4mvc-bounces at lists.typo3.org
[mailto:typo3-project-typo3v4mvc-bounces at lists.typo3.org] Im Auftrag von
Claus Due
Gesendet: Montag, 13. Juni 2011 12:50
An: TYPO3 v4 MVC project
Betreff: Re: [TYPO3-mvc] Cannot cast object
oftype"Tx_Extbase_Persistence_QueryResult" to string.
Hi Johannes,
It doesn't look like the code below would fail in this way. We probably need
to see your Fluid template to know the cause... this is possibly caused by a
misuse of {pages} or {variableNameYouEnteredInAsAttribute} after having
inserted the paginater...
--
Med venlig hilsen / Kind regards
Claus Due
Developer
--
Wildside A/S
Katrinebjergvej 113, DK-8200 Århus N
tlf. 86 12 64 65
http://www.wildside.dk
On Jun 13, 2011, at 12:39 PM, Johannes C. Schulz - EnzephaloN IT-Solutions
wrote:
> Thanks for the answer.
>
> So it might be possible, that the "stolen" paginate-widget throws the
error?
>
> <?php
> /**
> * Overwrite buildPagination Method
> Tx_Fluid_ViewHelpers_Widget_Controller_PaginateController
> *
> * @author Ralf Hannuschak
> */
> class Tx_EnzTeaserlist_ViewHelpers_Widget_Controller_PaginateController
> extends Tx_Fluid_ViewHelpers_Widget_Controller_PaginateController {
>
> /**
> * @param integer $currentPage
> * @return void
> */
> public function indexAction($currentPage = 1) {
>
> parent::indexAction($currentPage);
>
> // set current page
> $this->currentPage = (integer)$currentPage;
>
> // modify query
> $itemsPerPage = (integer)$this->configuration['itemsPerPage'];
> $query = $this->objects->getQuery();
> $query->setLimit($itemsPerPage);
>
> if ($this->currentPage > 1) {
> $query->setOffset((integer)($itemsPerPage *
> ($this->currentPage - 1)));
> }
> $modifiedObjects = $query->execute();
>
> $this->view->assign('contentArguments', array(
> $this->widgetConfiguration['as'] => $modifiedObjects,
> 'current' => $this->currentPage
> ));
> }
>
> /**
> * Returns an array with the keys "pages", "current", "numberOfPages",
> "nextPage" & "previousPage"
> *
> * @return array
> */
> protected function buildPagination() {
>
> $pages = array();
>
> $displayFirstPage = FALSE;
>
> $displayLastPage = FALSE;
>
> $this->numberOfPages = (int)$this->numberOfPages;
>
> if($this->numberOfPages > 5) {
>
> if ( $this->currentPage <= 3 ) { // page 1, 2, 3
>
> for($i = 1; $i <= 3; $i++ ) {
> $pages[] = array('number' => $i, 'isCurrent' => (
$i
> === $this->currentPage ));
> }
>
> if ($this->currentPage == 3 ) $pages[] = array('number'
> => 4, 'isCurrent' => false);
>
> $displayLastPage = TRUE;
> } else { // page 4 and more
>
> /* check last pages in case of 10 pages current page is
> page 9
> * should display : 1 ... 8 9 10
> * case page 8
> * should display : 1 ... 7 8 9 10
> */
> if($this->currentPage + 2 >= $this->numberOfPages ) {
> if($this->currentPage + 2 == $this->numberOfPages )
> $pages[] = array('number' =>
> $this->numberOfPages - 3, 'isCurrent' => false);
>
> for($i = $this->numberOfPages - 2; $i <=
> $this->numberOfPages; $i++ ) {
> $pages[] = array('number' => $i, 'isCurrent' =>
> ( $i === $this->currentPage) );
> }
>
> $displayFirstPage = TRUE;
> } else {
> /* display everything
> * case page 6
> * 1 ... 5 6 7 ... 10
> */
> for($i = $this->currentPage - 1; $i <=
> $this->currentPage + 1; $i++ ) {
> $pages[] = array('number' => $i, 'isCurrent' =>
> ($i === $this->currentPage) );
> }
> $displayFirstPage = TRUE;
> $displayLastPage = TRUE;
> }
> }
>
> } else {
> if($this->numberOfPages > 1 ) {
> // less then 6 pages so show all pages
> for($i = 1; $i <= $this->numberOfPages; $i++ ) {
> $pages[] = array('number' => $i, 'isCurrent' => ($i
> === $this->currentPage) );
> }
> }
> }
>
> $pagination = array(
> 'pages' => $pages,
> 'current' => $this->currentPage,
> 'numberOfPages' => $this->numberOfPages,
> 'displayFirst' => $displayFirstPage,
> 'displayLast' => $displayLastPage
> );
>
> if ($this->currentPage < $this->numberOfPages) {
> $pagination['nextPage'] = $this->currentPage + 1;
> }
>
> if ($this->currentPage > 1) {
> $pagination['previousPage'] = $this->currentPage - 1;
> }
>
> return $pagination;
> }
>
> }
> ?>
>
>
> -----Ursprüngliche Nachricht-----
> Von: typo3-project-typo3v4mvc-bounces at lists.typo3.org
> [mailto:typo3-project-typo3v4mvc-bounces at lists.typo3.org] Im Auftrag von
> Claus Due
> Gesendet: Montag, 13. Juni 2011 11:10
> An: TYPO3 v4 MVC project
> Betreff: Re: [TYPO3-mvc] Cannot cast object of
> type"Tx_Extbase_Persistence_QueryResult" to string.
>
> Hi Johannes,
>
> The function below looks good; the problem must stem from accessing the
> return value (a QueryResult) directly without iterating or using
> ->getFirst() - that would cause the error message.
>
> Could this be because of something done in Fluid using that QueryResult?
If
> so, it should help if you either iterate the QueryResult or use
> {queryResult.first} (I believe - can't remember wether the {var.first} is
> the proper way of getting the first record available from Fluid...
>
> --
>
> Kind regards
>
> Claus Due
> Developer
>
> --
> Wildside A/S
> Katrinebjergvej 113, DK-8200 Århus N
> tlf. 86 12 64 65
> http://www.wildside.dk
>
> Wildside er Danmarks mest kreative TYPO3-hus. Vi griber dine behov,
> tanker og sjove ideer og skaber unikke kommunikationsløsninger og
> websites. Vi tager hånd om hele processen fra idé til færdigt produkt,
> og vi hjælper dig, når løsningen går i luften.
>
> --
>
> Nyt produkt: Open Source webshops baseret på Magento Commerce
>
> http://www.wildside.dk/hvad-kan-vi/magento/
>
> On Jun 13, 2011, at 10:19 AM, Johannes C. Schulz - EnzephaloN IT-Solutions
> wrote:
>
>> Hi there!
>>
>>
>>
>> Today I have a problem with the error-message:
>>
>> Cannot cast object of type "Tx_Extbase_Persistence_QueryResult" to
string.
>>
>>
>>
>> I think something in my repository is wrong, but I didn't find it:
>>
>>
>>
>> class Tx_EnzTeaserlist_Domain_Repository_TeaseritemRepository extends
>> Tx_Extbase_Persistence_Repository {
>>
>>
>>
>> public function givemelist($category,$order,$type,$storage){
>>
>> $orderings = array($type => $order == 'ORDER_ASCENDING' ?
>>
>>
>> Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING :
>>
>>
>> Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING);
>>
>> if(!empty($storage)) {
>>
>> $pid = $storage;
>>
>> }else{
>>
>> $pid = t3lib_div::_GP('id');
>>
>> }
>>
>>
>>
>> $query = $this->createQuery();
>>
>>
>>
>> $pidsearch = array();
>>
>> if (!is_array($pid)) {
>>
>> $pidsearch =
>> $query->logicalOr(array($query->equals('teaseritem.pid',$pid)));
>>
>> }
>>
>> else {
>>
>> $pidsearch =
>> $query->logicalOr(array($query->in('teaseritem.pid',$pid)));
>>
>> }
>>
>>
>>
>> if(!empty($pidsearch))
>> $query->matching($query->logicalAnd($pidsearch));
>>
>> $query->setOrderings($orderings);
>>
>> return $query->execute();
>>
>> }
>>
>> }
>>
>>
>>
>> Can somebody help me please?
>>
>>
>>
>> Best regards
>>
>> Johannes
>>
>> _______________________________________________
>> TYPO3-project-typo3v4mvc mailing list
>> TYPO3-project-typo3v4mvc at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>
>
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
_______________________________________________
TYPO3-project-typo3v4mvc mailing list
TYPO3-project-typo3v4mvc at lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
More information about the TYPO3-project-typo3v4mvc
mailing list