2011-05-17 47 views
0

我使用symfony的1.4.11。我有下一個組件類:Symfony的尋呼機 - 成品的配件 - 查詢問題

class companiesComponents extends sfComponents { 

    public function executeCompanylist(sfWebRequest $request) { 



     // And the URL 
     if (!isset($this->url)) { 
      throw new Exception('Please specify the URL'); 
     } 

     // Save the page 
     if ($request->getParameter('page')) { 
      $this->setPage($request->getParameter('page')); 
     } 

     // Create pager 
     $this->pager = new sfDoctrinePager('Companies', sfConfig::get('app_ads_per_page', 5)); 
     $this->pager->setQuery($this->query); 
     $this->pager->setPage($this->getPage()); 
     $this->pager->init(); 
    } 

    protected function getPager($query) { 
     $pager = new Doctrine_Pager($query, $this->getPage(), 3); 

     return $pager; 
    } 

    protected function setPage($page) { 
     $this->getUser()->setAttribute('users.page', $page, 'admin_module'); 
    } 

    protected function getPage() { 
     return $this->getUser()->getAttribute('users.page', 1, 'admin_module'); 
    } 

我有行動:

public function executeAll(sfWebRequest $request) 
    { 
    $this->query = Doctrine_Core::getTable('Companies')->getAllCompany(); 
     $this->url = '@companylist'; 
    } 

而且我有allSucess.php

<?php include_component('companies', 'companylist', array(
     'query' => $query, 
     'url' => $url, 
     'noneFound' => __('You haven\'t created any ads yet.') 
     )) ?> 

在我的Companies Table類中

public function getAllCompany() 
    { 
    $q = $this->createQuery('a') 
    ->andWhere('a.active = ?',1) 
      ->leftJoin('a.Owner o') 
      ->leftJoin('o.Profile p') 
      ->andWhere('p.payed_until > NOW()') 

    ->addORDERBY ('created_at DESC'); 
} 

而且它不工作。我讓我所有的唱片「公司」從數據庫中,但他們沒有選擇根據我的查詢...... 當我做

public function getAllCompany() 
     { 
     } 

,或者當我評論

// $this->pager->setQuery($this->query); 

我仍然得到所有我的記錄:(

在日誌中我看到:

Template: companies … allSuccess.php 

Parameters: 
$query (NULL) 
$url (string) 

當我做

public function getAllCompany() 
    { 
    $q = $this->createQuery('a') 
    ->andWhere('a.active = ?',1) 
      ->leftJoin('a.Owner o') 
      ->leftJoin('o.Profile p') 
      ->andWhere('p.payed_until > NOW()') 

    ->addORDERBY ('created_at DESC'); 
return $q->execute(); 
} 

我有錯誤:

Fatal error: Call to undefined method Doctrine_Collection::offset() 

我不明白它是如何獲得的所有記錄,並在那裏我犯的錯誤:(

謝謝!

+2

安裝了XDebug,你就會有一個完整的堆棧跟蹤,而不僅僅是一條錯誤消息。順便說一下,它應該是'addOrderBy',而不是'addORDERBY' – greg0ire 2011-05-17 22:07:40

回答

2

刪除從getAllCompany()函數的返回語句->execute();文字...的DoctrinePager執行語句 - 你不需要......

public function getAllCompany() 
    { 
    $q = $this->createQuery('a') 
    ->andWhere('a.active = ?',1) 
      ->leftJoin('a.Owner o') 
      ->leftJoin('o.Profile p') 
      ->andWhere('p.payed_until > NOW()') 

    ->addOrderBy('created_at DESC'); 
return $q; 
} 
+1

謝謝!所有的作品,我忘了'返回$ q;' – denys281 2011-05-18 10:44:01