[TYPO3-mvc] Cannot cast object of type"Tx_Extbase_Persistence_QueryResult" to string.

Johannes C. Schulz - EnzephaloN IT-Solutions info at enzephalon.de
Mon Jun 13 12:39:44 CEST 2011


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




More information about the TYPO3-project-typo3v4mvc mailing list