Symfony pager - componets - query problem
I use symfony 1.4.11 .I have next component class:
class companiesComponents extends sfComponents {
public function executeCompanylist(sfWebRequest $request) {
// And the URL
if (!isset($this->url)) {
throw new Exception('Please specify the URL');
开发者_如何学JAVA }
// 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');
}
I have action:
public function executeAll(sfWebRequest $request)
{
$this->query = Doctrine_Core::getTable('Companies')->getAllCompany();
$this->url = '@companylist';
}
And I have allSucess.php
<?php include_component('companies', 'companylist', array(
'query' => $query,
'url' => $url,
'noneFound' => __('You haven\'t created any ads yet.')
)) ?>
In my Companies Table class
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');
}
And it is do not work. I get all my record "companies" from database,but they are not selected according to the my query... When I make
public function getAllCompany()
{
}
or when I comment
// $this->pager->setQuery($this->query);
I still get all my records :(
In logs I see :
Template: companies … allSuccess.php
Parameters:
$query (NULL)
$url (string)
When I make
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();
}
I have error:
Fatal error: Call to undefined method Doctrine_Collection::offset()
I do not understand how it get all records, and where I made mistake :(
Thank you!
remove the ->execute();
text from the return statement in the getAllCompany() function ... the DoctrinePager executes the statement - you don't need to ...
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;
}
精彩评论