【问题标题】:Symfony pager - componets - query problemSymfony 寻呼机 - 组件 - 查询问题
【发布时间】:2011-05-17 21:27:29
【问题描述】:

我使用 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() 

我不明白它是如何获取所有记录的,以及我在哪里出错:(

谢谢!

【问题讨论】:

  • 安装 XDebug,您将获得完整的堆栈跟踪,而不仅仅是错误消息。对了,应该是addOrderBy,而不是addORDERBY

标签: symfony1 symfony-1.4 pager


【解决方案1】:

从 getAllCompany() 函数的 return 语句中删除 -&gt;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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-07
    • 2011-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多