Пейджер Symfony — компоненты — проблема с запросом

Я использую symfony 1.4.11. У меня есть следующий класс компонентов:

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.')
        )) ?>

В моем классе таблицы компаний

   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() 

Я не понимаю, как он получает все записи, и где я ошибся :(

Спасибо!


person denys281    schedule 17.05.2011    source источник
comment
установите XDebug, вы получите полную трассировку стека, а не только сообщение об ошибке. Кстати, должно быть addOrderBy, а не addORDERBY   -  person greg0ire    schedule 18.05.2011


Ответы (1)


удалите текст ->execute(); из оператора return в функции getAllCompany()... 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;
}
person Manse    schedule 18.05.2011